Significant Whitespace

Alex R. Young





programming style

Significant Whitespace

Posted by Alex R. Young on .

programming style

Significant Whitespace

Posted by Alex R. Young on .

In his homoiconic blog, Reg
recently discussed jQuery
because he heard that it "changes the way you think about programming".
In Significant
Reg discusses how jQuery embraces the use of chained calls on separate
lines to increase readability:


He makes an interesting stylistic point:

To keep the logic clear I've been using the following style guideline: When I'm returning the receiver, I do not indent.

So when he returns something else from a chained call, he indents:

  .parents('body > *')

He likens more complex chained and indented calls to
haml and sass. JavaScript isn't aware of the level of indentation, but he suggests that
this could be useful, and relates this to jQuery's end()

His last point is what really made me understand his arguments:

I have some other reasons for wanting this in the language that have to do with destructuring assignment, pattern matching, and other uses for code that looks like the data it manipulates.

Even though his hypothetical language would be interesting,
understanding end() can trip up jQuery beginners working on
other people's code. I've had to untangle deeply nested ends before and
it's one of those things that encourages me to finish work early and hit
the beer. If you're feeling a little bit lost, the end()
makes it all clear once you
work through the examples.