You're right that the bare super keyword is a bit of an odd-duck ... it exists because the 90% use-case for super is to forward all of the arguments that your overridden function received. Currently, you just write:
myFunc: ->
super
... but if we didn't have that, you'd have to do something more like this all the time:
myFunc: ->
super.apply(this, arguments)
Having loops that function as loops when you use them as loops, and function as comprehensions when you try to use their value, is a pretty core feature. It's a nice conceptual simplification, and if we removed it, then the story would be: everything's-an-expression-except-for-loops, which would be a bit sad.
You're right about different-distance dedenting. I think the reason why it's valid is to support use-cases like this:
object.method a, b,
c, d
... but we could probably do better to detect cases that are obviously incorrect, and flag them as syntax errors. Feel free to open a ticket if you'd like to get this rolling.
I disagree. The rule that implicit parentheses (generally) follow, is that they extend to the end of the line, or to the end of the block that ends the line. To riff on your examples, it allows for uses like this:
print message or defaultMessage
bank.deposit currentBalance + incomingCheck
... and if you need tighter binding, you simply write the parens:
total = bank.lookup("checking") + bank.lookup("savings")
This is not possible now in CoffeeScript
Oh, but it is ;) If you don't mind the new line, block strings gobble-up all of the left-hand indentation for you: http://coffeescript.org/#strings
The thing I sometimes run into in CS is that defining a lambda as the first argument of a function when there are more than one argument does only work if you put the thing in brackets:
The rule that implicit parentheses (generally) follow, is that they extend to the end of the line, or to the end of the block that ends the line.
Hmm, good point. However, that encourages what I see as 'floating arguments'. Extending to the end of the line is a good idea if it doesn't meet an operator, like the example on the front page:
console.log sys.inspect object
Furthermore, I think it would be good to encourage wrapping a long argument with operators in parenthesis.
If you don't mind the new line
That's the problem :)
A common example is a long URL which are sensitive to new lines, extra spaces, etc. I think the current implementation of double quoted, multiline strings is very limited as it only works properly in the outermost scope, otherwise it doesn't respect indentation, making the code look out of place (and interfering with Vim's folding ;) ).
Is there a way to disable implicit parenthese entirely? I like a lot of what's in CoffeeScript but that class of behaviour has lead to bugs, usually subtle, in every language where I've encountered it.
... but if we didn't have that, you'd have to do something more like this all the time:
myFunc: -> super.apply(this, arguments)
That could be solved with more generalized sugar along the lines of Python's super(*arguments), which would eliminate the need for the unusual special-case and be applicable elsewhere.
I'm not sure that super is actually the cause of my issues here though. Probably a bigger factor is that I'm a fan of the following syntax, which makes me overly used to seeing function names with nothing after them for calls:
obj.foo
name: 'a'
className: 'btn'
Having loops that function as loops when you use them as loops, and function as comprehensions when you try to use their value, is a pretty core feature. It's a nice conceptual simplification, and if we removed it, then the story would be: everything's-an-expression-except-for-loops, which would be a bit sad.
I disagree about it actually being a simplification, since I see "loop over a list of items and trigger side effects" and "transform a list of values into a different list of values" as fundamentally different algorithms, and deciding which algorithm to use is outside the scope of what a compiler should be doing.
Probably not worth writing more words on this unless this is somehow a novel argument that you haven't seen.
You're right about different-distance dedenting. I think the reason why it's valid is to support use-cases like this:
object.method a, b, c, d
That merely requires variable-width indenting. The case that's problematic is the following:
a = ->
b
c: d
e
f
g
I can't really imagine any reason why one would want to do this intentionally, and a, f, and g all being treated as the same indentation level is really weird. Python solves this by requiring that dedents return to a previously used indentation level, which makes e an error without breaking the above sensible formatting.
everything's-an-expression-except-for-loops, which would be a bit sad.
It could still be an expression, just one that always evaluated to undefined. The return expression doesn't have a meaningful evaluated value either, for that matter. (Which is natural, of course, since there would be no way to capture it.)
View all comments
Show parent comment
9
u/jashkenas Jul 25 '13
Thanks, that's helpful.
You're right that the bare
superkeyword is a bit of an odd-duck ... it exists because the 90% use-case forsuperis to forward all of the arguments that your overridden function received. Currently, you just write:... but if we didn't have that, you'd have to do something more like this all the time:
Having loops that function as loops when you use them as loops, and function as comprehensions when you try to use their value, is a pretty core feature. It's a nice conceptual simplification, and if we removed it, then the story would be: everything's-an-expression-except-for-loops, which would be a bit sad.
You're right about different-distance dedenting. I think the reason why it's valid is to support use-cases like this:
... but we could probably do better to detect cases that are obviously incorrect, and flag them as syntax errors. Feel free to open a ticket if you'd like to get this rolling.