Hacker Newsnew | past | comments | ask | show | jobs | submit | GeZe's commentslogin

FYI, it would not be accurate to say that "The Flow people moved on to ReScript".


Another example would be the difference between their enum features: https://medium.com/flow-type/typescript-enums-vs-flow-enums-... "TypeScript Enums vs. Flow Enums"


Flow also supports "discriminated unions" [0], and did so before TypeScript (Flow's announcement in July 2015: https://flow.org/blog/2015/07/03/Disjoint-Unions/, TypeScript's announcement in August 2016: https://devblogs.microsoft.com/typescript/announcing-typescr...), though it doesn't yet support destructuring the "kind" field as was just added to TypeScript.

[0] https://flow.org/try/#0C4TwDgpgBAggxsAlgewHZQLwCgq6gHygG8oBr...


Here are the docs for exporting/importing enums: https://flow.org/en/docs/enums/using-enums/#toc-exporting-en... - works fine with the new export/import syntax.

Docs for enums compilation/runtime are here: https://flow.org/en/docs/enums/defining-enums/#toc-enums-at-...


That's very cool, thank you so much.


You can similarly search/replace JS code, but using pattern matching and CSS style selectors instead of writing code, with Grasp. It's usable from the command line like sed.

http://www.graspjs.com/

For instance changing all calls to "calc" from taking two arguments to taking one object literal instead (eg. `calc(1, 2)` to `calc({from: 1, to: 2})`, is as easy as:

    $ grasp -r -e 'calc($a, $b)' -R 'calc({from: {{a}}, to: {{b}}})' file.js
(Where the two arguments to "calc" could be any arbitrary nested expressions, which could not be safely handled by a regular expression)


(Disclaimer: I'm maintaining jscodeshift)

Yes, this is great! I'd love to be able to integrate graspjs with jscodeshift somehow. Ideally there would be multiple possible ways to find the nodes you want to change (pattern matching, tree traversal, etc), and multiple ways to specify how to replace them (e.g. a template like in your example vs a function where you can do anything you want).

Simple transforms should definitely be possible with little "code" like in your example and we certainly have to improve jscodeshift in this regard.


For a tool dedicated to searching and replacing JS in this way (AST aware), check out http://graspjs.com

You can use both CSS style selectors, and pattern matching, to both search and replace your code.


Self was one of the inspirations behind JavaScript, particularly its prototype system.

http://en.wikipedia.org/wiki/Self_(programming_language)


I spent some time with Self in the late 90s (at college of course!) and it was impressive on several counts: first, it's JIT compiler allowed Smalltalk to run faster when implemented in Self than without - the same JIT technique was later re-used in Java Hotspots [1]; second, the programming environment was a multi-user environment called Kansas that allowed a whole classroom of students to develop "prototypes" in the same environment (Kansas [2] [3])

[1] http://www.princeton.edu/~achaney/tmve/wiki100k/docs/Self_(p...

[2] http://web.media.mit.edu/~lieber/Lieberary/Softviz/CACM-Debu...

[3] http://bluishcoder.co.nz/2013/09/16/multiple-users-in-a-self...


Except for the part where what Self calls prototype has no equivalent in javascript (constructors are close to Self's `copy` message, but not quite the same) and what javascript calls prototype Self calls mixin (or traits, depending whether they've got ancestors up to the lobby themselves). And a Self object can have multiple mixins and add or remove them at runtime.


The "JavaScript is like Self" fallacy is just another variant of the "JavaScript is like Scheme" fallacy. It sounds great to the person claiming it, and to an unsuspecting audience. But on closer inspection, the similarities between the two languages are minimal at best.


Newtonscript was also a descendent. Although I like Objective-C, I do miss Newtonscript and the soup. Prototype-based programming often had a nicer feel than [edit]class[/edit] systems.

http://newtonscript.org - look at the "SELF and the Origins of NewtonScript" down the page


Looks like someone has started one: https://github.com/joneshf/sublime-grasp


Cool project! As monjaro mentions, the two examples are not equivalent however - the grasp example replaces every binary expression (alias: bi) with an addition operation with the right and left hand sides switched. This is a very trivial example, but hints at the great power available.

Grasp has two different query types, the default, squery - selector query, CSS style selectors, and equery (-e, --equery) - example query, JS code examples with wildcards.

In the grasp example above, we are using squery. jsgrep is similar to equery. You could do the following search in equery, and it would be more equivalent to the example you posted:

    f(__ < __, __ == __)
The only thing missing is the named wildcards for easy replace - that's a good idea and a feature to add to grasp 0.2.0!

You can check out the docs on squery (http://graspjs.com/docs/squery/) and equery (http://graspjs.com/docs/equery/)


I plan to add support for both LiveScript and CoffeeScript to grasp in the future.

PS. If anyone has any questions about grasp please let me know!


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: