I've been using CoffeeScript for a while. I find it a good language overall, certainly better than plain JS, but I find I'm still baffled by its indentation rules. Take this example:
Bacon.mergeAll(
@searchButton.asEventStream('click')
@searchInput.asEventStream('keyup')
.filter (e) => e.keyCode is 13
)
.map =>
@searchInput.val()
.flatMapLatest (query) =>
Bacon.fromPromise $.ajax
url: @searchURL + encodeURI query
dataType: 'jsonp'
This does what it should (the code is based on this tutorial, btw) but it took me a lot of trial and error to get it right.
Why do mergeAll
and asEventStream
require parentheses around their arguments? Why is indentation not enough to determine where their argument lists begin and end? OTOH, why is indentation enough for map
and flatMapLatest
? Why is the whitespace before a hanging method, such as .filter
(its indentation level) not enough to determine what it binds to? It seems to be completely ignored.
Is there a definitive guide to this language's indentation rules? I never had a problem understanding Python syntax at a glance, even with very complex nesting, so it's not an issue with indentation-based syntax per se.