4 ms·
From C99 and C++, also Java, `const` does not affect the bound value. It's a declaration keyword, so it affects only how to bind the declarator name or names th
by BrendanEich 8y ago
From C99 and C++, also Java, `const` does not affect the bound value. It's a declaration keyword, so it affects only how to bind the declarator name or names that follows immediately. This is all stating the obvious, but expecting effects on the initialiser will lead only to frustration, on two counts:
1. JS is in the C/C++/Java lineage syntactically. Ok, that is a deeper design flaw, but Netscape management to keep Sun on board said "Make It Look Like Java".
2. If you want declarations to affect captured expressions, you'll soon want a type system if not immutability controls and defaults. IOW, at least Scheme-like binding rules and set! as special form to use when mutating. Again the ships sailed 23+ years ago, and in truth for "Mocha's" target audience, immutable-by-default would have been harder to use.
"They just start writing and see what works" => a primary design goal. Flawless Victory! :-)
Seriously, the Scheme in the browser baby was killed in the cradle; the recruiting bait used to get me on board was snatched away because of the Sun/Netscape Java deal. All is not lost, as JS grows better special forms (but for backward compatibility must keep old ones). Among these, `const` is least better but still useful.
What's more, those who advocate mass-market immutable-by-default are still working to make it usable in the large (e.g., in Rust). Pedagogy helps, but also has not delivered the goods yet. We are living through the full experiment to refine and confirm that i-b-d is best.