jashkenas/coffee-script — Issue #1897: Omit () in chaining
Author: johnnywengluu
Created: 2011-11-27 19:52:22+00:00
State: open

I usually do like this:

Db.fetch()
.start("n=node(2)")
.match("(n)-[r:KNOWS]->(c)")
.return("n")
.on (data)->
console.log data

However, since I am using the dot (.), a new line and indentation, couldn't all the () be removed like this:

Db.fetch
.start "n=node(2)"
.match "(n)-[r:KNOWS]->(c)"
.return "n"
.on (data)->
console.log data

Often when we do chaining we will begin each method call in a new line and indent so the methods are aligned.

I think using the dot (.) is sufficient to tell it's a chaining call. This could even be used as a one liner?

Db.fetch .start "n=node(2)" .match "(n)-[r:KNOWS]->(c)" .return "n" .on (data) -> console.log data

If this somehow the dot isn't enough we have the new line and indentation as a confirmation that it's a chaining method call.

Here is another example:

I usually write a method call with arguments like this:

require "x"

But then I have to get a specific class and have to go back and change it to:

require("x").Class

This is happening all the time (not just with require) and makes me wanna just use () in the beginning so I don't have to add them later when I need to chain. But I love the readability and how clean the code is without the ().

In that example it would be better just to allow me to:

require "x"
.Class

Or

require "x" .Class

Thoughts about this?