I'm certainly aware. Like everything else, eliminating shadowing in this particular way is a tradeoff. When you're introducing new variables at the top level of the file -- something that's pretty rare, that the patch did -- you certainly have the possibility for conflicts. But shadowing also has a possibility for conflicts -- by var'ing a variable in an intermediate scope, you can break an inner scope's access to an outer variable.
The difference is that a compiler can detect the latter, so the cost is that you spend 1 second compiling your program, get an error and rename the conflicting variable.
When you reuse a name in CoffeeScript, the cost is a bug that can go undetected for a long time.
You haven't gained this:
Keeping variable names descriptive and singular within a lexical scope, and removing the need to even think about "has this variable been declared in the right place", is a huge boon, in my opinion.
because you can get it in a language with explicit variable declarations too! All you've gained is not typing "var", at the cost of obscure bugs.
Implicit variable declarations are a choice I hope no language designer ever makes again.
View all comments
Show parent comment
2
u/rwbarton Jul 26 '13
The difference is that a compiler can detect the latter, so the cost is that you spend 1 second compiling your program, get an error and rename the conflicting variable.
When you reuse a name in CoffeeScript, the cost is a bug that can go undetected for a long time.
You haven't gained this:
because you can get it in a language with explicit variable declarations too! All you've gained is not typing "
var", at the cost of obscure bugs.Implicit variable declarations are a choice I hope no language designer ever makes again.