r/programming • u/zumpiez • Dec 22 '11
The Problem with Implicit Scoping in CoffeeScript
http://lucumr.pocoo.org/2011/12/22/implicit-scoping-in-coffeescript/
83
Upvotes
r/programming • u/zumpiez • Dec 22 '11
View all comments
Show parent comment
1
u/jashkenas Dec 22 '11 edited Dec 22 '11
Yes, what you describe is absolutely the case. The value of a variable becomes transparent to the lexical scope -- but it's the entire lexical scope.
I think the bit about reducing the conceptual complexity stands. You may have a bit more scope to cover, and a bit more work to do to read it, but the whole idea of "declaring a variable" is gone, the idea of "shadowing a variable" is gone, and the potential for the same variable to have multiple values within a single lexical scope is gone. My premise is that to a beginner, it's simpler.
Fortunately, in most well-factored bits of JavaScript, lexical scopes tend to be quite shallow. You may have a few helper functions floating around at the top level, but that's probably it -- and you're certainly aware of what they are. In practice, accidental shadowing rarely comes up (Armin's case being one example), and when it does, picking a better name will always solve it.
But hey, we're programmers -- we're used to declaring variables and shadowing them. It's hard to give up that power ... even if you don't really need it.