5 ms·
Thanks! That's very nice, among possible backward compatible solutions I cannot imagine a better one. Now I wonder what kind of fix the CoffeeScript folks will
by cousin_it 13y ago
Thanks! That's very nice, among possible backward compatible solutions I cannot imagine a better one.
Now I wonder what kind of fix the CoffeeScript folks will make, when they admit the problem...
- masklinn 13y agoI don't think they can fix that one in CS short of changing the semantics of the language: they decided to infer scope (an error as far as I'm concerned) and because they wanted to avoid shadowing they went with generalizing scope inference (as opposed to Python, which always infers function-local scope unless specifically told otherwise, scope inference is still bad but slightly less so as it won't suddenly turn a local variable into a global one without warning due to a non-local change). I believe CS tried to copy Ruby as block scope inference works the same way, but Ruby uses its method/block duality to mitigate the issue: scope inference is generalizing across the (lexical) blocks of a method, but the inference stops at the method, if you assign to a name at the top-level (global) and assign to a name in a method you will create two different bindings. Coffescript has no such duality, and as a result can't use it for a "watertight seal" around scoping.
- cousin_it 13y agoGreat examples, I agree that conflating declaration and assignment seems to be a mistake that different languages try to mitigate in different ways. Another example is in http://www.paulgraham.com/arclessons.html http://www.paulgraham.com/arclessons.html, "Implicit local variables conflict with macros."