Why Do All the Great Node.js Developers Hate CoffeeScript?
procbits.com
procbits.com
https://github.com/raganwald/homoiconic/blob/master/2011/12/...
So I suppose I'll have to just say that looking at the article itself and argue the content rather than the packaging. So here's the premise: A bunch of great JS developers aren't also CS developers.
Possibility #1: Correlation == Causation. Writing CoffeeScript rots your brain and makes you unfit for writing great Node.js code.
Possibility #2: Writing great Node.js warps your brain such that CoffeeScript is unpalatable.
Possibility #3: Writing great Node.js code means you're very comfortable with JS itself and your tool chain, and thus you look askance at any switch.
I'd say that both #2 and #3 are far more likely than #1. Neither of them imply that you shouldn't use CS today if it seems appealing.
#4 pretty much the only advantage of CoffeeScript is saving a few keystrokes, not worth spending time on
#5 most of your day is still spent reading javascript, the mental overhead of switching between JS and CS all the time makes it unappealing
#6 using javascript makes for writing better javascript libraries than coffeescript
#4 needs some clarification. If you're making a global statement, then you're contradicting my experience and the statements of many CS users. Agree or disagree, clearly it's "debatable" and not axiomatic accepted fact.
Or you might be saying that for some developers, including the quoted node developers (and possibly yourself), there are insignificant benefits. I listed the possibility that the node developers saw no significant return on investment, so if that's what you're saying, then we agree.
Exactly, I read your comment in this style (which seems to have been correct according to what follows my quote) and decided to use the same. These were not intended to be understood as the absolute truth brought down from the mountain.
Although some of these points do roughly match my thinking (if I'm going to learn a not-JS-but-compiles-to-it, I'd rather use something drastically different which can bring significant gains — e.g. Roy or ClojureScript — or build -my-own via SweetJS than limited syntactic sugar)
(a) -> (b) -> (c) -> ((x) -> (y) -> (z)) is readable and understandable in coffee script the same is not true for javascript, but it's just a 'few extra keystrokes' to do the same thing in Javascript.
Same thing in mathematics, it's just a few extra keystrokes to express 2 ^ 3 ^ 4 ^ 6 ^ 7 in basic addition, same thing with calculus and algebra.
The point is valid in the trivial case but as soon as you start looking at saving a few keystrokes as a 'expressive power' then it makes a lot of sense to use a language like coffeescript.
Once you start using the expressive power of a higher order language, it's an order of magnitude more keystrokes in the less expressive language.
My (mild) knock against it is that it doesn't introduce any new abstractions. No special sauce for continuations or promises, for example. But that is obviously a two-edged sword, it eschews new semantics by design.
Well, I suppose you could also say that the reason I might use Ruby over Java is to "save a few keystrokes". I'm exaggerating to make the point that shortcuts for common tasks are important.
- String interpolation (`"foo#{bar}baz"`)
- Existence unary operator (`foo?`, `foo ? "bar"`)
- Splats (`(foo, bar...) ->`)
- Comparison chaining (`10 < foo < 20`)
- Loops and comprehensions (`x() for x in ["foo", "bar"]`)
- Destructuring (`[foo, bar] = items`)
- Ranges (`num for num in [1..10]`)
- Array slicing (`items[3..5]`)
- Object properties (`for own key, value of object`)
I think these are all substantive improvements to JavaScript, not even taking into account readability-improving sugar like post-conditions.
CoffeeScript's advantages - clarity and concise code - are outweighed by the feeling of building on an abstraction, and narrowing your contributor base. This feeling may be increasingly inaccurate: a lot of people write coffeescript, it's pretty well integrated nowadays.
I'm not sure why you're claiming to speak for the other nine developers listed in the post.
It's a good point that tmcw makes. Plenty of developers, including Jeremy Ashkenas (creator of CS), write their open-source library stuff in vanilla javascript while hacking away with CoffeeScript for other things which don't rely on community contributions.
I've had no problems debugging or understanding CoffeeScript and while I'm not at the level of a Jon Resig, I can more than hold my own with Javascript. CoffeeScript is just syntax and generally safer than plain Javascript. It will declare vars for you if your forget. It will use an optimized for loop. It will put a wrapper around code to minimize leaks ...
I'm not arguing what the article seems to circle around to near the end - that CoffeeScript is worth trying - but its nominal premise seems a little shaky. Perhaps those developers simply feel as I do, that Javascript syntax is fine and there's not that great of an incentive to switch. I actually like braces and semicolons, and I definitely prefer function literal syntax to arrow syntax.
Which makes it all the stranger that experienced JavaScript developers seem to avoid it, while less experienced ones embrace it.
My main gripe with CoffeeScript (there are a couple, but here's one) is code organization/readability when a method takes multiple functions as arguments.
foo ->
bar()
baz()
quux()
, (error) ->
throw error if error
That does look a bit odd, and you run into these a lot when you're using caolan/async. You can avoid this by avoiding anonymous methods, but with so many callbacks in Node.js that is probably less readable. foo(
->
bar()
baz()
quux()
(error) ->
throw error if error
)In fact, I've been using CoffeeScript to postprocess data from molecular simulations (supercomputer output). It's about 3x less code than an equivalent C program and requires a lot less thinking so I can get things done quicker. But I tend to use CoffeeScript in a functional style (which in my opinion is the best language paradigm for handling a lot of data).
Systems developers provide services for other developers; generally they want to minimize dependencies. It doesn't make sense to write foundational tools in CoffeeScript unless all the clients of those tools will be written in CoffeeScript as well. Otherwise you're just adding complexity to their projects and making them harder to debug.
This is a common reason I've heard. Here's the bottom line, CoffeeScript is not javascript.
Suppose you want to speak Japanese but only know English. Google comes out with Translate 4.0 that does realtime translation on the fly. Great! Now you can speak Japanese, right? No.
Most of the devs I've personally interacted with that like Coffeescript are conversely bad at javascript. Admittedly this is anecdotal and only based on my personal experiences.
Learn javascript. Get a book, read some tutorials. Quit trying to squirm around just because closures make you nervous.
I don't particularly like Java compared to some other options, but I still code in it most, simply because of the huge number of libraries and developers who use it. It's very difficult to write any big project by yourself, which means you need others, which means you need to not use obscure languages and other technologies that prevent working together. I much preferred writing for Linux PDAs than I do writing for Android smart phones, but if I did that, no one would use my stuff. :)
However, I don't like _using_ CoffeeScipt. It immediately shuts out the other 85%+ of JavaScript users who aren't familiar with CoffeeScript from reading and understanding my code.
The other gripe I have is that debugging it is a pain in the ass since errors that come back reference the javascript code, not the coffeescript. Apparently this is a problem being worked on but it's still irritating.
I do agree on the debugging aspect. I always have to go back to the compiled javascript to understand errors. Can you please point me to solutions being worked upon in this regard? Open source?
But overall I agree; I wish they'd fixed the JS quirks that they did, allowed indentation instead of braces, added their lambda syntax, and stopped about there. It goes too far on optional syntax and functional features that are gradually being added to JS anyway.
Yes, I could go look at the output, or go really learn it, but if my goal is to produce javascript then it's just another leaky abstraction on top of something that isn't that hard to do by hand. If my choices were CoffeeScript or ASM, then I'd choose CoffeeScript in a heart beat.
In general i don't really feel comfortable with code-generating layers that abstract away what i want (and need) to know. I want to look into the Chrome Devtools, see "line 23 in bla.js" and correlate that to the source in my editor. Same reason i don't use all that less/sass/haml etc. etc.
But for me, JavaScript's shortcomings are far worse than CoffeeScript's.
Not all browsers have support for source maps, and sometimes you really need to debug browser specific behaviours without having to debug generated code along the way.
Additionally in most teams I work on, it is often the case that besides myself no one even knows what CoffeScript is.
CoffeScript just adds more code to debug without any real benefit.
Then again, that may change when I get a lot more comfortable using Node. At the moment I just prefer to know exactly what's going on under the hood.
var i=3; function x() { alert(i); var i=5; } x();
and why is this powerful? I agree with you mostly, but I don't like this 'feature'.
Edit: hoisting yes, but why, besides compiler optimization is it more powerful for the programmer than if it would not do hoisting, or, why is it in a modern language like JS?
Edit1: I'm not in favor of coffeescript I used Javascript most of the time during my work day, I was just seriously wondering, if not for low level optimization why it would be a problem to have global scope until local is defined.
I think it is dirty, but the point of the var statement (and your hoisting example) is that you implicitly imply the variable scope. In Coffeescript, you just do an assignment and it will be function scope if it (the variable) doesn't exist in any parent scopes? That seems dirtier to me and dangerous.
If you are awesome and namespacing and keeping clean/modular/maintainable code, Coffeescript may work great.