In the process of maintaining this blog, I was reintroduced with CoffeeScript. I first read about CoffeeScript in 2009 but I never learned it and I soon forgot about its existence.
For the past 2 weeks I have been learning and practicing CoffeeScript and I wrote this article to share my excitement.
A syntax centered around brevity
CoffeeScript borrows strict indentation and list comprehensions from Python, optional parenthesis around method calls (there are exceptions to this rule) and implied
return statements from Ruby.
These features reduce keystrokes which, of course, reduce development hours.
When CoffeeScript is compiled, the script is wrapped in a closure thusly:
This will ensure that your script will execute as intended without error.
Automatic boilerplate injection
For example, if you use the method
indexOf(), you ought to write a routine which creates the method
CoffeeScript takes care of this for you.
This is best shown through example. This straight-forward class:
Is compiled into this monstrosity:
Reduced syntax errrors
Live compilers like JS2coffee allow you to write and validate CoffeeScript in realtime. Use this to find syntax errors.
Makes you look like a master