And did you know that it’s currently the eleventh popular language on Github?
But wait, another language ?
Striclty speaking, CoffeeScript is a language like any other. But behind the curtains, it feels more like SASS to CSS than a truly different language to learn.
It may be off by twenty lines on a long script, given small differences accumulates, but finding the original code that compiled to what is seen in Firebug is really easy as you’ll see along this article. Sourcemap is on its way, thanks to CoffeeScriptRedux
Anyway, let’s get started:
Translates to :
Just from this example can be notice the first borrowings. CoffeeScript uses tabs to handle code blocks, getting rid of curly braces like Python. There’s also the implicit return borrowed from Ruby.
The function keyword is replaced by the ->, arguments are placed at the before the keyword, in a mathematical fashion.
It also comes with very useful additions, like automatic lexical scoping. Declaring variables is implicit and it behaves exactly like the original one, given a value is affected to the variable.
CoffeeScript throws == out through the window, == being translated to ===. Given the amount of bugs it avoids, it’s already a damn good reason to adopt CoffeeScript.
Release the kraken
Hordes of little additions that makes a programmer’s life much more easier are baked in:
There’s also shortened syntax, to build one liners that don’t looks like egyptian glyphs :
To ice the cake, CoffeeScript borrows a killer feature from Python, list comprehensions :
And many others
The list of supported constructs is available on the [official website](http://cffeescript.com) and it fits a single page. That’s how light CoffeeScript is.
You’ll find a better syntax to declare objects (hashes), array slicing and ranges, new operators and aliases, a clean syntax for class inheritance with a super keyword and even a provides a => instead of -> to handle this in callbacks.
It’s worth noticing that if => is used instead of -> in class definitions, it will bind the method to the current instance, allowing it to be passed around callbacks without having to manually binding before.
other way around, you can write some CoffeeScript code that will be used
For example, using jQuery :
It had been packaged for every major framework in most popular
languages, so it can be quickly installed : Rails, Django 1 and 2, Symfony, Play.
And to learn more about Coffeescript, just wander on its official