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/dherman Dec 24 '11
In a C-style loop, the programmer is mutating the variable on each iteration, possibly in the loop body but also in the loop head. So the programmer saying "here are some variables, and here's how to update them on every iteration of the loop." It's inherently about mutation. If you give a fresh binding, what looks like a mutation of a shared variable actually becomes implicitly copied into a new variable on each iteration; the semantics has to take the final value of each local and copy it as the initial value of a fresh binding for the next iteration.
We've discussed this in the past on es-discuss: https://mail.mozilla.org/pipermail/es-discuss/2008-October/thread.html#7819
The weirdness of changing the mutation of a shared variable into an implicit copy was always sort of self-evident to me, so I never really gave Dart's current semantics much thought. I'm still skeptical, but given how commonly people are bitten by the combination of nested closures and C-style for loops, it's worth considering.