Description
I know assignment scope has been discussed at length for CS2 (#4951), but I don't see a discussion in the context of CS3. So here it is.
Block scope =
I'm strongly in favor of changing =
from var
to let
and using nearest block scope instead of function scope, as was proposed by @jashkenas here: coffeescript6/discuss#58 (comment)
Shadowing avoidance
There was also talk of adding a :=
operator for explicit avoidance of shadowing.
Another option is the let
keyword (which invites inclusion of const
).
Just today, I thought of :foo = 1
as another option.
Concerns
@jashkenas said in coffeescript6/discuss#58 (comment):
There should only be one way to declare variables in CoffeeScript. Not having to think about two different mental models of variable scope at the same time is precisely and specifically the raison d'etre of CoffeeScript in the first place.
..which rules out the :=
operator, but maybe not let
or :foo =
?
If =
is changed to block scope, the shadowing problem can be fixed without having two mental models of variable scope.
In the same comment, @jashkenas said:
If y'all think that block scoping is inherently superior to function scoping, (I too feel that way, but only lukewarmly), then the time to make the breaking change is now. CS2 is the only big breaking change we've had in 6 years — so do it now, or don't do it at all.
..but I assume this discussion is still "up in the air" for CS3.
Let me know if I missed any other ideas or concerns.