5 ms·
The "try coffeescript" demo (http://jashkenas.github.com/coffee-script/ http://jashkenas.github.com/coffee-script/) is really cool. It converts to javascript in
by 10ren 16y ago
The "try coffeescript" demo (http://jashkenas.github.com/coffee-script/ http://jashkenas.github.com/coffee-script/) is really cool. It converts to javascript in realtime/as you type, including error checking on the fly.
I like the lambda syntax (I don't recall seeing exactly this syntax before):
() -> alert("lambda")
(() -> alert("lambda")) () # to call it
- jashkenas 16y agoCoffeeScript lets you leave off parentheses when they're not necessary to describe what you mean. Your example can also be written as: -> alert 'lambda' (-> alert 'lambda')() # to call it
- d0m 16y agoIt's a matter of opinion, but I don't particularly like when you can "omit" things.. and sometime it works and sometime it doesn't. Yes, sometime it makes the code a little clearer, but it can often lead to sneaky bugs and confusion. I mean: map x -> xx seq might be readable .. but: map x -> xx seq seqs is less clear.. while: (map (x -> x*x) (seq seqs)) is more readable.
- aaronblohowiak 16y agoit also increases the friction when you are editing; the question in your mind must be "does this edit require the implicit to be made explicit?" Editor support can help alleviate the drudgery of the change, but I prefer to pay up-front.
- djacobs 16y agoaaronblohowiak, I wonder if "pay up front" is analogous to pre-mature optimization? I'm thinking out loud, mainly because I tend to use the simplest syntax possible when coding in languages that allow for multiple syntaxes (i.e., Ruby). Most of the time, my decisions (at least) work out for me, and I don't have to go back and (say) add parentheses.
- jashkenas 16y agoMy two cents on optional parentheses, optional commas, and optional syntax in general are that it's about readability and style. If the statement that you're writing isn't clear without disambiguating the structure, then by all means, use parentheses. But if you're choosing between this: print("Hello"); And this: print "Hello" (Which are equivalent in CoffeeScript) ... I'll take the latter every time.
- gnaritas 16y agoThat's very similar to the C# syntax () => expression arg => expression arg, arg2 => expression arg => { statement; expression }