Coffeescript isn't consistent.
setter = (arg) -> store = arg
store = 'initial'
is quite different from store = 'initial'
setter = (arg) -> store = arg
This is a practical problem since it means that the most commonly used JS encapsulation feature - closures - become harder to write. Suddenly assignments that have no direct influence on each other cannot be blindly reordered (which is a pain), and in particular closures that have a bunch of helper functions defined initially that need to ensure that local variables are set before the helpers, even if those local variables are themselves functions.It's just a mess. Frankly, I think javascript does this part a lot better than coffeescript, especially now that "use strict" exists and you can get some feedback when your scoping assumptions turn out wrong, rather than a silent failure and unexpected behavior.
Re:The worst thing about CoffeeScript
by aaron-lebo on Saturday January 25, 2014 @01:26PM
(#7121682)
It is a bigger issue than lack of familiarity.
It can lead to some really unexpected bugs. There is a reason most languages don't do things this way.
http://lucumr.pocoo.org/2011/12/22/implicit-scoping-in-coffe...
This is also a problem with javascript. Javascript should do automatic variable shadowing but also throw a warning.
>The worst thing about CoffeeScript is that you are used to having scoping work a different way?
No, the issue is that he's used to having scoping work properly.
Coffeescript behavior corrects a wrong (shadowing) with an even worse wrong. Even worse, as a default it can affect variables outside of the function, so it breaks locality.
Re:The worst thing about CoffeeScript
by mattdeboard on Sunday January 26, 2014 @09:48PM
(#7128431)
I suspect, but don't know, this is different in Python 3, since `print a` changes from a statement to an expression.
Let's extend your example:
So Python does take from the outer scope? Or not? Or it just doesn't work at all?Next time, pick a better example. The answer to "What does Python do with a variable from outside a function's scope?" is "It depends."
At least CoffeeScript is consistent.