`const` was a mistake
120,716
Published 2024-05-19
Ugh.
Original rant (unlisted for now)
• A Rant About F***ing Const vs F***ing...
SOURCES
www.epicweb.dev/talks/let-me-be
twitter.com/cramforce/status/1786608749354082455
github.com/TodePond/DreamBerd/tree/main?tab=readme…
www.joshwcomeau.com/javascript/the-const-deception…
Check out my Twitch, Twitter, Discord more at t3.gg/
S/O Ph4se0n3 for the awesome edit 🙏
All Comments (21)
-
Can't we just agree to default to const and use let when we want to re-assign a variable. It's so useful and nice and helps readers and helps even you the developer.
-
Ah, the good old let-leaning vs constervative
-
If you’re in a company that runs a meeting about const vs let quit immediately
-
ES2026 will come with `const const` to indicate that it is truly immutable and we will also get a quadruple equal sign ==== to indicate that the thing is truly truly equal.
-
"Defaulting to `const` actually makes 'let` mean something" (paraphrasing of course)
-
const is not to protect us from mutation, it is to protect us from javaScript
-
I can't believe I'm writing this, but does Ryan seriously not understand the difference between constant assignment and immutability? This is the dumbest hill I've ever seen anyone climb. 100% agreed on your convention, this is what I've been doing for years already
-
At this point choosing JavaScript as my main programming language is the only mistake I made.
-
This presentation's argument is just so useless, because it is based on the premise, that writing "const" is intenting to mean "the whole structure is immutable", when it means "the name cannot be bound to another value than the initial one". JS isn't by far the only language with semantics like that. So this is rather a skill issue/(intentional) misinterpretation than an argument. Addendum: Mutability of bindings is different than mutability of their contents –Have fun getting your "export let" or "export function" destroyed by assignments on a star-import! (ESMs export bindings not values and "function"+
has the same semantics as "var" bindings!) -
When I encounter "let" in the code, it stored in some part of my brain. Expecting to find it again later in the code where the value changes. By using "const" for constant value instead of "let". The number of brain energy spent to hold those information are reduced greatly.
-
to me the meaning of JS's const is that it's always the same object, not that it's immutable. clear and simple. and quite important for dealing with mutability too: if you mutate it in one place, all other places are guaranteed to observe the change.
-
i will unsubscribe if this is a serious thing
-
The conference talk feels like a troll
-
Ah yes, JS devs discussing stupid shit with ridiculous arguments and fallacies
-
In C++ you can absolutely change both the memory that a pointer points to, as well as the address of the pointer. There's a whole can of worms about `const int* someName` vs `int* const someName` vs `const int* const someName` vs `int const* someName` which is pretty annoying to deal with. The older I get, the more I appreciate a really good implementation of const-ness, and in C++ we're closing in on that with constexpr and consteval
-
Const means you can't rebind the thing. That's really important to know. It doesn't mean the thing is a constant. Once you know that, just use const by default, and use let where necessary, which points out which variables change and which ones don't. This isn't rocket science or something.
-
off-topic: as someone who's taken my fair share of LSD, and known people who've taken way way way more than their share...i'm still struggling with Ryan's take away about LSD: "it's pretty undisputed that LSD has wrecked many, many lives" like -- compared to what? and in my experience, which i consider broad, as a travelling musician and ne'er-do-well, i just don't see people abusing LSD like i do other substances. or beliefs. it's not without harm, of course, nothing is. i just don't know anyone who was "wrecked" by it, per my definition of "wrecked". or "by". i support him not drinking coffee and acknowledge nothing is without side effects. i'm just bloody confused here. i'm also a programmer so i am here for a reason! i'm working on an ESP8266 project but in 20 years of off and on dev work this is my first serious foray into C++, and in an embedded environment, i honestly thought the dilemma was twixt #define macros and const. anyway. i look forward to a settled resolution. edit: boy howdy was i unprepared for all of this, dear lord
-
"LSD has wrecked many lives" (X) Doubt
-
One good thing about "const" is that it basically tells you that it's type of "data structure" is constant, so if we do this: const arr = [1,2,3], arr will always be array, even if content changes, if it was "let", you can assigng arr= "123", and it is now a string. Another reason and intention we can provide.
-
2:35 this is not true, albert hofmann worked for a pharma company that was researching something against bleeding in pregnancies. Not adhd related.