CoffeeScript: less typing, bad readability
Just because you CAN do something in CoffeeScript doesn't mean you SHOULD, or should ALL of the time.  Just like in JavaScript where, if you want, you can write all of your code on one line, but you shouldn't.<p><pre><code>    action true
      option1: 1
      option2: 2
</code></pre>
If you really use CoffeeScript regularly, that isn't confusing.  I don't usually write it that way though.  I would do this:<p><pre><code>  options =
    a: 1
    b: 2
  action true, options
</code></pre>
doSomething () ->  'hello' just isn't valid code.<p>Usually I would write<p><pre><code>    doSomething ->
      return 'hello'
</code></pre>
or maybe<p><pre><code>    doSomething -> 'hello'
</code></pre>
If you write it the way he did, the parenthesis are confusing.<p>For this one:<p><pre><code>    action = (token, i) ->
        @tokens.splice i, 0, @generate 'CALL_END', ')', token[2]
</code></pre>
-- first of all, you always want to indent two spaces.  But the main problem with that is in CoffeeScript you do need to use parenthesis after the first call because your code will be unreadable otherwise.  You just can't write it the way he did.<p><pre><code>    moveTo 10,
      20
      10

    doSomething 1,
    2
    3
    4

    doSomething 1,
      2
        3
       4
</code></pre>
Those are ridiculous examples.  No one does that.  You just write moveTo 10, 20, 10<p><pre><code>    doSomething (->
    'hello'), 1
</code></pre>
Indentation is significant in CoffeeScript, just like it is in Python.  Just having a parenthesis shouldn't change that.  Anyway, what I do is this:<p><pre><code>    somethingDo = (ms, func) ->
      doSomething func, ms
</code></pre>
and then I can just write<p><pre><code>    somethingDo 1, ->
      'hello'



    action(key: value, option: value, otherValue)
</code></pre>
You don't write it like that if the function takes two objects.  You would probably just write<p><pre><code>    action {key: value}, {option: value}, otherValue


    x = {
      key1
      key2
      key3: value3
    }
</code></pre>
This is called destructuring assignment, and its part of the new ECMAScript.  Its useful to not have to repeat key1, key2 everywhere when the variable with the value has the same name as the object property.  The extra curly braces are just necessary to differentiate from the normal syntax.<p>Sometimes yes/no or on/off are more readable than true/false.  That's an advantage.<p><pre><code>    x = 1 if y != 0;
</code></pre>
Don't use semicolons in CoffeeScript.  I also don't put if statements at the end of a line because I don't believe that is very readable for most people including me.  Also, in CoffeeScript its probably better to use isnt instead of !=, although rather than !=, you would want !==.<p><pre><code>    if y isnt 0
      x = 1
</code></pre>
I'm not that sure about the use of unless, although it probably is a little bit more readable overall.<p><pre><code>  break for [tag], i in @tokens when tag isnt 'TERMINATOR'
  @tokens.splice 0, i if i
</code></pre>
He says that is supposed to delete TERMINATOR from tokens.  I tested it, it doesn't do anything, and the second example of the correct way doesn't work either.  I think he meant this:<p><pre><code>    filtered = []
    for token, i in tokens
      if not (i is 0 and token is 'TERMINATOR')
        filtered.push token


    i += block.call this, token, i, tokens while token = tokens[i]
</code></pre>
Another example of something you CAN do in CoffeeScript but shouldn't.  Actually it is a bad idea in general.  I think a CoffeeScript programmer would actually write something like this:<p><pre><code>    class Parser      
      block: (token) =>         
        @currentNode.push new Token(token)
      parse: =>
        for token in tokens
          @block token
        </code></pre>
I would never write something like 'mainModule.moduleCache and= {}'<p>Instead of<p><pre><code>    js = (parser.parse lexer.tokenize code).compile options
</code></pre>
I would write<p><pre><code>    tokens = lexer.tokenize code
    parsed = parser.parse tokens
    js = parsed.compile options</code></pre>