-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CS2 Discussion: Features: const assignment operator #4927
Comments
From @zeekay on 2016-09-07 07:24 I prefer matching JavaScript here. It's less confusing to newcomers, matches compiled output exactly, etc. Seems preferable for a minor ES6 feature of limited utility. As I would much rather see |
From @GeoffreyBooth on 2016-09-07 07:25 I take it back, I didn’t notice that |
From @lydell on 2016-09-07 07:54 I tend to use |
From @zeekay on 2016-09-07 08:14 I can see the value of I would still prefer |
From @DomVinyard on 2016-09-07 09:01 I'll drop my opinion on this here by way of completeness (#30). I strongly believe that the concept of an exposed |
From @rattrayalex on 2016-09-08 04:41
that's not true for many people; see the discussion in #1 .
that's not true for many coffeescript developers either 😉 |
From @rattrayalex on 2016-09-08 04:42 How parseable would |
From @GeoffreyBooth on 2016-09-08 04:51 If we could somehow automatically choose What’s lost by automatic I think we could, potentially, automatically assign variables with |
From @rattrayalex on 2016-09-08 05:19 I don't quite see the point in an inferred const? (As discussed elsewhere). If people want pretty output they can use decaffeinate. |
From @lydell on 2016-09-08 05:55 Personally, I don't care about any theoretical performance benefit or something like that by using |
From @GeoffreyBooth on 2016-09-08 06:01 So @rattrayalex and @lydell want the explicit “I want the compiler to fail if I reassign this variable” while @DomVinyard and @greghuc in #30 want to preserve “I don’t need to think about how my variables are assigned.” We get the former with |
From @JimPanic on 2016-09-08 07:00 👍 for explicit Implicit const is not worth implementing. There is absolutely no benefit to it. |
From @mrmowgli on 2016-09-10 05:29 +1 for explicit. For both const and let. Unfortunately it seems that const refers only to the reference of the variable not changing, rather than variable immutability. Perhaps |
From @GeoffreyBooth on 2016-09-10 23:30 @JimPanic there is actually a benefit to implicit if (true) {
var a = 1;
let b = 2;
const c = 3;
}
console.log(a); // 1
console.log(b); // Uncaught ReferenceError: b is not defined
console.log(c); // Uncaught ReferenceError: c is not defined Also theoretically runtimes should be more performant with |
From @GeoffreyBooth on 2016-09-12 06:56 I’m starting to think it doesn’t make sense to implement only |
From @GeoffreyBooth on 2016-09-16 04:02 I’m going to close this in favor of #35, unless anyone objects. |
From @rattrayalex on 2016-09-16 04:04 I object 😉
Regardless of whether |
From @GeoffreyBooth on 2016-09-16 04:12 How would you deal with the side effect that outputting |
From @rattrayalex on 2016-09-16 04:19 A line of documentation 😉 |
From @rattrayalex on 2016-09-16 04:20 The ability to declare some variables as block, and some as lexical, is a "feature" of JavaScript, bless-its-heart. |
From @rattrayalex on 2016-09-16 04:20 And the number of times when you really don't want coffeescript's current scoping, and really want block scoping instead, and can't use const, is probably extremely low. |
From @GeoffreyBooth on 2016-09-16 04:24 I think if we introduce into CoffeeScript the ability to declare a block-scoped variable, we can’t force it to be unreassignable. If we give people Maybe the times when someone would want |
From @rattrayalex on 2016-09-16 04:45
In theory, that's true. In practice, we can give the one without the other, and very few people will run into difficulties. |
From @rattrayalex on 2016-09-16 04:46 However, if you'd like to propose completely replacing ... in any case, I personally think this thread should be kept alive for discussion, regardless of whether you think it will ultimately make sense to merge. |
From @GeoffreyBooth on 2016-09-16 04:54 I disagree that the amount of times people would want I’m not convinced we should mess with variable assignment. Perhaps one |
From @mrmowgli on 2016-09-16 07:10 We definitely don't want to take away the ability to use var when they expect it. Especially when dealing with closures. |
From @jcollum on 2016-09-16 Keep in mind I'm not any good at writing transpilers: why not just let people use
|
From @GeoffreyBooth on 2016-09-16 @jcollum there’s no reason the transpiler couldn’t. It was a core design decision of CoffeeScript, though, that developers wouldn’t have to think about variable declaration. That’s why CoffeeScript groups together all variables used in a scope to a Not everyone agrees with this design decision, clearly. And they may have more ammo to their argument since ES2015 introduced |
From @jcollum on 2016-09-16 I like the design principle of "Use a default but allow people to override it". I'd prefer not to use backticks to override it. 2¢ |
From @GeoffreyBooth on 2016-09-17 See this comment. I really don’t think allowing |
From @GeoffreyBooth on 2016-09-07 06:49
Branching off from #1 and #30, I thought it would be good to have a thread dedicated to discussing the proposed new operator for explicitly declaring and assigning a variable as a
const
. This thread is not for debating automaticlet
assignment, or whether we should change other things related to variable assignment. Justconst
. For other topics, please comment on other issue threads.The consensus from #1 seems to be to add an
:=
operator that works like=
, but declares and assigns a variable as aconst
. So:becomes:
This has the advantage that it’s not a breaking change; currently
:=
fails to compile. There is no need to support?:=
, since by definition constants can’t be reassigned.Nothing else would be changed by adding this new operator. Normal assignment is handled as it is today, with
var
. Even though using:=
would causeconst
to be in the generated output, this feature is “opt in” like modules and the same warning would apply about transpiling CoffeeScript’s output.If people like the idea but disagree with the syntax, I invite you to propose an alternate syntax that isn’t a breaking change. Simply following ES2015, with a syntax like
const foo = 42
, is an option sinceconst
is already a reserved word in CoffeeScript.So I think the debate is: should we add this at all? And if so, this syntax or some other backwards-compatible syntax?
The text was updated successfully, but these errors were encountered: