3 ms·
My biggest problem is that because it lacks firm rules in a lot of area, CoffeeScript is a language that is not always intuitive. With JavaScript it's pretty si
by MatthewPhillips 15y ago
My biggest problem is that because it lacks firm rules in a lot of area, CoffeeScript is a language that is not always intuitive. With JavaScript it's pretty simple to know the rules; they are completely uniform. Not so with CoffeeScript. Here's my biggest gripe:
greet = (greeting, person) ->
"#{greeting} #{person}!"
greet "Hello", "world"
That's simple. A function that takes 2 parameters, separated by a comma. But wait, here's another:
longRunning = (onsuccess, onerror) ->
dosomething (e) ->
if not e.error? onsuccess() else onerror()
And the implementation:
longRunning
() -> "Yippee!"
() -> "Oh noes"
A function with 2 parameters, this time separated by a carriage return, not commas. How would one know that intuitively? That some times functions parameters are separated by commas and some times by carriage returns? Or that some times function calls have to include the () (when they have no parameters) and some times they don't (when they do have parameters)?
I'm sure these things become second nature over time, but learning them will result in a lot of trips to StackOverflow as you wonder why your code doesn't behave as expected.
- jashkenas 15y agoOne wouldn't know that intuitively, because what you wrote: longRunning () -> "Yippee!" () -> "Oh noes" ... is not valid CoffeeScript. I'm not sure where you got that from. Ideally, you'd write it: longRunning onSuccess, onError Or, if you really wanted to use two inline functions instead of local variables: longRunning (-> "Yippee!"), (-> "Oh noes")
- MatthewPhillips 15y agoThanks. A more realistic example would, I suppose, look like this: longRunning (-> ### bunch of stuff happening for success ### ), (-> ### bunch of stuff happening for failures ### )
- jashkenas 15y agoYes, that'll work fine, as will this, if you prefer: longRunning -> # bunch of stuff happening for success , -> # bunch of stuff happening for failures