3 ms·
better variable scoping CS's scoping is a bit... dangerous, because there's no indication of a variable's scope. If you're not paying attention to your environ
by dmpk2k 14y ago
better variable scoping
CS's scoping is a bit... dangerous, because there's no indication of a variable's scope. If you're not paying attention to your environment, you'll inadvertently stomp on higher scopes or globals. You can lose assignments through typos too.
JS made a mistake by allowing globals by omitting "var", but that at least can be worked around by using a linter or "use strict". A number of languages have made this mistake, and many later followed a similar path to fix it.
CS has a lot of nice properties, but we should not laud conflating variable definition and assignment. It has always been a mistake, and I hope CS's author eventually comes around and fixes it.
- jashkenas 14y agoIt's been much discussed, but I'm afraid I'm still very strongly of the opinion that it's an idea that yields positive benefits -- and we should continue to do as much to avoid shadowed variables as possible. Always open to debate though, and note that other dialects (Coco, perhaps LiveScript) have added another operator to distinguish higher scoped assignments.
- eurleif 14y ago>CS's scoping is a bit... dangerous, because there's no indication of a variable's scope. If you're not paying attention to your environment, you'll inadvertently stomp on higher scopes or globals. You can lose assignments through typos too. Not just that, but adding a variable to an outer scope can break functions that were previously just fine. Isn't the whole point of scoping that changing code in one place won't affect unrelated code in another place?