HTML5 Zone is brought to you in partnership with:

Chris Smith writes coffeescriptlove.com, a fan blog dedicated to that devastatingly elegant "little language that compiles into JavaScript." He loves programming, and software development in general, with a career arc that traces the ascendance of Java, then that of Ruby on Rails, and is now aligning with the power and possibilities of today's browser technologies. He is currently writing an interactive ebook on Backbone.js and CoffeeScript (backbonecoffeescript.com). Chris is a DZone MVB and is not an employee of DZone and has posted 17 posts at DZone. You can read more from them at their website. View Full User Profile

CoffeeScript Style Guide

05.17.2012
| 3000 views |
  • submit to reddit

You may have come across the GitHub JavaScript Styleguide, which tells us to:


"Write new JS in CoffeeScript." 

 That alone is an awesome endorsement of the "little language", but there is more good advice:

"Follow @jashkenas's style. See the documentation for good examples." 

Without doubt, this is correct. The CoffeeScript home page should be your first stop for style. However, it's not strictly a style guide, so for a more dedicated resource I recommend polarmobile/coffeescript-style-guide. It answers questions such as "tabs or spaces?", and I expect it will continue to grow, becoming a very comprehensive resource.


Of course, you could argue that in the age of computer automation, the best style guides are linters. CoffeeLint is described as "a style checker that helps keep CoffeeScript code clean and consistent." For style consistency across a team, it's likely to be a great choice.


Finally, as an example of good CoffeeScript style in the context of hairy, real-world programming, Jeremy Ashkenas recommends the source code for the Pow server.


This list is by no means complete and is open for your contributions. Where do you go for great CoffeeScript style?
Published at DZone with permission of Chris Smith, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)