I've been trying to apply PEP8 as closely as possible to CoffeeScript.
Are there any other coding conventions you follow?
Load a remote script from the current domain via XHR. Activate CoffeeScript in the browser by having it compile and evaluate all script tags with a content-type of text/coffeescript . This happens on page load. Listen for window load, both in decent browsers and in IE.
CoffeeScript with Node and npm msi on Windows and install node from http://nodejs.org/dist/v0.6.6/ — See http://nodejs.org/dist/ for newer versions. Open a command line. On Windows 7 right-click and select 'Run as Administrator' when starting the terminal. On Mac OS X you can use 'sudo' when starting the npm command.
CoffeeScript was created by Jeremy Ashkenas and first released on December 25, 2009. The original compiler was written in Ruby. The compiler was rewritten in CoffeeScript and released in March 2010. For its syntax CoffeeScript borrows heavily from Ruby, Python, and of course JavaScript.
I use the postfix form of if/unless only for guard constructs:
return if not valid
break if finished
continue if not important
Not for assignments:
mood = greatlyImproved if singing
My reasoning is based on the condition being hidden off to the right and a control flow path being on one indentation level.
When I look at a block of code, I can scan down the left and can see the control flow. Code which follows a return is obviously only reachable if the return only happens sometimes, so it stands out. It's a recognizable pattern and having it in one line is better than two.
An assignment doesn't stand out however and it's easier to overlook the condition on the right. If an assignment only happens sometimes, I think an if with indentation is clearer:
if singing
mood = greatlyImproved
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With