3 ms·
Certainly, by far the "most controversial thing about CoffeeScript". Fortunately, CoffeeScript is open-source, and can be both easily changed, and easily forke
by jashkenas 13y ago
Certainly, by far the "most controversial thing about CoffeeScript".
Fortunately, CoffeeScript is open-source, and can be both easily changed, and easily forked to suit your fancy. There are very nice versions (LiveScript and Coco, for example), that change this behavior by introducing two different types of assignment — if that sort of thing is your cup of tea.
... and if anyone has a specific proposal about how they'd like to see this feature changed in order to improve it, feel free to open a ticket for discussion — it could very well happen. For example, making this:
topLevelFunction = ->
path = "a/b/c"
... many lines of code go here ...
path = require('path')
... into a compile-time error, with some sort of "Subsequent variable shadows `path`" warning, that would be something worth talking about.
- emn13 13y agoThe fact that it's open source doesn't help: using and maintaining a similar but subtly different version of coffeescript is worse than living with this bug since it means your code is now incompatible with the rest of the world's. Not to mention you're likely to train yourself to misread "real" coffeescript. As to the ticket; A quick search would have revealed there are many tickets on the topic of shadowing: https://github.com/jashkenas/coffee-script/search?q=shadowing&ref=cmdform&type=Issues https://github.com/jashkenas/coffee-script/search?q=shadowin... And this ticket covers this specifically https://github.com/jashkenas/coffee-script/issues/2697 https://github.com/jashkenas/coffee-script/issues/2697 and was closed.
- moomin 13y agoI think Jeremy is being a bit disingenuous here. There are many good reasons for not wanting to fork a language, and getting a change made to CoffeeScript is frustrating and glacial. To be clear, I understand why this is: bad decisions are hard to reverse. Unfortunately, the specific issue raised at the top is a poster-child for bad decisions that are hard to reverse.
- jayferd 13y agoI don't know if this can be solved without a syntax change. As long as there is variable binding and variable mutation are conflated in the syntax, there's really no good way for the compiler to distinguish between the two. It's an unfortunate design decision that we may be stuck with if we want back-compat. LiveScript is interesting, but seems to have Too Many Features for my tastes.