The ECMAScript 6 specification is approaching its approval, and with it are a number of great features. Should we stop writing CoffeeScript altogether and start using the upcoming ES6?
It appears that it is still too early to put CoffeeScript in its grave. There is still something that makes CoffeeScript more attractive than vanilla JS for everyday use: its syntax.
Many great features of CoffeeScript have already been implemented in ES6, but CoffeeScript remains full of those little things that make everyday jobs easier:
- You don't have to think about hoisting, vars, lets or returns.
- Syntactic sugar such as
unlesskeywords or one line conditionals
- Code is cleaner without
- Time savers:
# Splat arguments: race = (winner, runners...) -> print winner, runners # Existential operator: alert "I knew it!" if elvis? # Conditional assignments: date = if friday then sue else jill # Chained comparisons: healthy = 200 > cholesterol > 60
Curly braces are fine
Most JS programmers don't understand what Coffee programmers have against curly braces or semicolons. The C-like syntax is just fine. How can a couple of extra characters be an argument against language quality?
In practice, less characters means less code, which could result in less bugs. It's easier to catch errors when you have less visual noise. Navigating a file is easier with 20 lines of code rather than 50. Also CoffeeScript won't let you write un-indented code, no matter how lazy you are.
CoffeeScript is harder to understand than plain JS
It is largely a matter of habit. CoffeeScript does take some learning, but so will the new EcmaScript 6 syntax. It is sometimes hard to see the benefits of it before you start using it for real.
One of the arguments against CoffeeScript syntax was that it is too obscure for JS programmers and only understandable by people with backgrounds in languages such as Ruby. Now, as some of the CS syntax is part of the future of JS itself, I believe that this argument has been put to rest.
It doesn't support ES6 features
Yet. There is no logical reason to believe that good ES6 features won't be also implemented in CS once they become widely supported. Until then, there is no reason to make a language that compiles into another compiled language.
You need a pre-compiler
One of the strongest argument against CoffeeScript is that you will need a compiler for it forever, while the need for the ES6 compiler will be eventually eliminated.
If you use SCSS or Autoprefixer with Grunt or, even better, Gulp, to handle compilation (and you probably should) then using CoffeeScript is as simple as writing a few lines of code and you are ready to go. And with sourcemaps, you can also debug it easily in browser.
By the way, if you look at the ES6 Compatibility Table, you will see that there are still too many red cells to say that you won't need a compiler in the near future. It may take months if not years before all browsers will support all features of the next ECMAScript spec.
The truth is, there are people out there using CoffeeScript to write awesome products like Atom, Discourse, Github, Dropbox, Hubot, Pow, or Koding IDE.
The bottom line