jashkenas / jashkenas/coffeescript

CS3 Discussion: Assignment scope

Open
#4,985 26 comments 0 reactions 0 assignees View on GitHub
change
Dominant language
CoffeeScript
Stars
16.6k
Forks
2k
PR merge metrics
No merged PRs in 30d

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: https://github.com/coffeescript6/discuss/issues/58#issuecomment-265220724

 

### 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 https://github.com/coffeescript6/discuss/issues/58#issuecomment-265193752:
> 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.

Contributor guide

Open the contributing guide

Research direction

Start by reading the referenced CS2 discussion in #4951 and the linked comments in coffeescript6/discuss#58, then compare the proposed block-scope and shadowing options. Done would require a settled CS3 assignment-scope design before any implementation work can be scoped.

Written by the indexing model from the issue text.

Assessment

Tech stack
coffeescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.