Skip to content

Instantly share code, notes, and snippets.

@rhumlover
Last active August 29, 2015 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhumlover/c0bfc068b661f8282738 to your computer and use it in GitHub Desktop.
Save rhumlover/c0bfc068b661f8282738 to your computer and use it in GitHub Desktop.
Why CoffeeScript for a non-ruby developer?

Pros:

  • readability: so nice to get rid of semicolons and curly braces, loops are amazingly transparents
  • allows a real "class"-based work. It's perfect if you work with Backbone, for instance. Might be less true with Angular and such
  • defines some meaningful shortcuts, to create functions or closures for example. Next version of EcmaScript learned about it and will feature the "arrow" notation for functions
  • it pairs perfectly with CSS preprocessors, but mainly SASS: focus on the content, less on the appearance

Cons:

  • you need to perfectly know how JavaScript works. The CoffeeScript output is really nice, but writing it can lead to unexpected side-effects (forgot double arrow instead of single arrow), real prototype inheritance, difference between class properties, instance properties, scopes
  • you might want to focus on bad ways to improve performance. For instance, CS knows that defined functions inside loops are bad, so it will generate a function outside the loop and call it inside. If later you move on pure JavaScript, you might want to do the same, without thinking of moving out the function declaration

So, an amazing thing overall if you are building a good MVC app, like Backbone-based apps. It might be less relevant with components, Angular, but still nice to use for its readability.
The main important thing is: know your JavaScript before writing in CoffeeScript. The contrary will lead to very bad JS developers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment