3 ms·
I like to have the flexibility to indent in whatever style the code calls for. That said, looking over the Python docs again, their implementation of significan
by jashkenas 17y ago
I like to have the flexibility to indent in whatever style the code calls for. That said, looking over the Python docs again, their implementation of significant whitespace is a lot more flexible than I remembered. I didn't realize you could do one-line method definitions, and that the whitespace only kicks in when you write a multi-line block.
Here's a question for you. In Python, if you have a couple of nested lambdas with multiline bodies, getting passed into each other as arguments, do you have to write the closing parenthesis on the correctly-indented line on the other side, or can it be tucked against the inner lambda?
In a hypothetical significant-whitespace CoffeeScript, I'm thinking of this:
elements.each(el =>
el.click(event =>
el.show()))
Versus this:
elements.each(el =>
el.click(event =>
el.show()
)
)
Is the second form required to make Python-style whitespace work?
- aaronsw 17y agoNo.
- jashkenas 17y agoGreat. Then let's start a "whitespace" branch, and give it a go. Edit: Alright, got a branch that starts with a little significant whitespace going here: http://github.com/jashkenas/coffee-script/tree/whitespace http://github.com/jashkenas/coffee-script/tree/whitespace It can't handle the first of the two cases mentioned above just yet, but it compiles the second one correctly.
- scott_s 17y agoPython does not have multiline lambdas. But Python only uses significant whitespace when it can't use other demarcations. For example, the following is legal: a = [ 1, 2, 3]