ExploreTrendingAnalytics
Nostr Archives
ExploreTrendingAnalytics
hodlbod5d ago
`const` in javascript was a mistake (like most things in javascript)
💬 23 replies

Replies (23)

EVAN KALOUDIS5d ago
let it go
0000 sats
hodlbod5d ago
and use rust? With the machine's help I am finally giving that a go
0000 sats
Sync5d ago
Avoided it like the plague
0000 sats
jimbocoin 🃏5d ago
0000 sats
Pip the WoT guy5d ago
why?
0000 sats
J.G.Montoya.Hodl5d ago
What's the problem with `const`?
0000 sats
Brunswick5d ago
Const is for compiled languages, not scripted languages. The closest concept to a const in a scripted language is an enum.
0000 sats
EVAN KALOUDIS5d ago
Typescript, but Rust is even better
0000 sats
hodlbod5d ago
Typescript still has the let/const dichotomy. I held on for a long time, but adopted ts in 2023
0000 sats
Hayward5d ago
"Glad to hear you’ve embraced TypeScript! It’s fascinating how languages evolve over time. Whether it’s let/const or something else, every tool has its quirks. Here’s to your coding journey in 2023! 🚀"
0000 sats
hodlbod5d ago
😂
0000 sats
hodlbod5d ago
I (and the LLMs) spend way more time switching between const and let because the linter tells us to than relying on something not being reassigned because it's declared with const. If you need const, your scopes are too big.
0000 sats
Nuh5d ago
Just use Rust everywhere... If LLMs are so good, what is the purpose of JavaScript at this point?
0000 sats
hodlbod5d ago
I've already stubbed out a re-write of welshman in rust. I don't know how it'll turn out, but I'm definitely interested in the idea
0000 sats
Pip the WoT guy5d ago
so you want const to be used only for global constant, for example const SecondsInDay. Correct?
0000 sats
ChipTuner5d ago
Yeah const everything. mutable is a smell for me. If I have to use a mutable variable I'm probably doing something hacky.
0000 sats
hodlbod5d ago
Sure, but the language's conventions are very reliant on reassignment. And const doesn't prevent mutation anyway. I say this as someone whose favorite language is clojure
0000 sats
ChipTuner5d ago
True, but it allows for an immutable pattern in an designed mutable language (which is an argument against const existing at all). const does prevent assignment, just not mutation of the object. Same could be said for C (also my favorite language). Const just changes the compiler enforced memory location protection. I'm trying to make sense of this argument though. I suppose, coming from strongly typed/functional languages into JS, I developed my own idiomatic patterns to sidestep the designed mutability of the language. I would also agree in theory that const as a concept in JS shouldn't exist if it was true to the way it's taught.
000
hodlbod5d ago
The necessity to go back and forth between `let` and `const` depending on whether a variable is reassigned isn't worth the mental overhead conserved by knowing that a variable isn't reassigned provided by `const`
0000 sats
hodlbod5d ago
Just do `let SECONDS_IN_DAY` and call it good
0000 sats
0 sats
ChipTuner5d ago
To your point https://git.vaughnnugent.com/cgit/vnuge/plugins-essential… Usually I would gate this functionality behind a branch to avoid reassigning a variable. It's very rare for me to use a mutable variable except in a very controlled scope. In some parts of this library I've wrapped with getters and setters.
0000 sats
hodlbod5d ago
Encapsulation assumes developers are dumb and will shoot themselves in the foot. They are, and they will, but I prefer my code to have affordances for me to do weird things. But a big part of that is the difference between being a one-man team with comprehensive knowledge of the codebase and being on a larger team with shared institutional knowledge. My complaint is less about const, which is a good idea, than about linters wasting my time by making me switch back and forth. The number of times const has saved me doesn't compensate for the busy work of pleasing the linter.
0000 sats
Floppy PNG5d ago
I use the Deno linter. While I find it beneficial in my code to differentiate const and let, it can be turned off fairly easily. https://docs.deno.com/lint/rules/prefer-const/
0000 sats