CoffeeScript Style Guide

I am trying to apply PEP8 as close as possible to CoffeeScript.

Are there any other coding conventions that you follow?

+8
coffeescript
source share
1 answer

I use the postfix if / if form only for defensive 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 fact that the condition is hidden on the right, and the control flow path is at the same level of indentation.

When I look at the code block, I can scan left and see the control flow. The code that follows the return is obviously available only when the return happens sometimes, so it stands out. This is a recognizable pattern and its presence on one line is better than two.

However, the assignment does not stand out, and it is easier to skip the condition on the right. If assignment occurs only occasionally, I think if indented is clearer:

 if singing mood = greatlyImproved 
+10
source share

All Articles