I’m so sorry! @wycats warned me const was a mistake for this exact reason and I didn’t take it seriously enough. One of my main ES6 regrets.
1: The point of const to me is to let the user know that the original author INTENDED it to be immutable.
-
-
2: By saying "always use const and change it whenever it happens to be mutated", you're losing an important signal:
-
3: That the original author considered it questionable to mutate the variable.
-
4: And what are we gaining? In exchange for losing user intent, we gain a minor but noisy piece of metadata ...
-
5: that is trivial to see by scanning the code (is it mutated is the same as "is there an x= somewhere in the function?")
-
6: If your functions are too large for it to be quickly analyzable, consider smaller functions.
-
7/7: Your code will be clearer and you won't have given up an important source of user intent.
-
I’m guilty of using “const” everywhere I can out of habit, but I doubt it has really ever prevented a bug.
-
It also devalues the meaning of const when you wrote it for a reason ("don't change this module-level variable plz")
- 3 more replies
New conversation -
-
-
I thought you were talking about C++ for the entire thread and I was *extremely* confused :P
-
Haha. The story is different in rust :)
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.