May 8, 2012

CoffeeScript Style Guide

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?