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
3
u/gwillen Dec 23 '11
I realize I'm just some guy on the Internet, but: I don't think the alternative model (in which each iteration of the loop is a fresh scope) is that odd. It matches the model used in lisps, where iteration is supposed to feel like tail recursion so it would be odd if each iteration weren't a fresh scope. It also matches one of the two models available in Perl, which distinguishes between:
and:
Thus it would feel natural to me for something like your snippet above to bind i freshly each time through the loop, and for the other behavior to be available by choosing to bind i above the loop. (This does not, I admit, square particularly well with the actual syntax, in which the 'var' or 'let' appears in the initialization section of the loop, and appears to only be run once; but it would be really nice to have some concise way to get these semantics.)