r/programming • • Jul 25 '13

CoffeeScript's Scoping is Madness

http://donatstudios.com/CoffeeScript-Madness
207 Upvotes

315 comments sorted by

View all comments

Show parent comment

5

u/Plorkyeran Jul 26 '13

... 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.