In the small, it's much less useful. It's distracting to the reader of the code to be constantly informed "this binding is not mutated" 4/
-
-
Worse, it's confusing people because it's not telling you the value is immutable, just the binding. 5/
2 replies 3 retweets 13 likes -
Replying to @littlecalculist @wycats
I feel like your point is strong, but I've never known a dev to miss the distinction between mutable vs const name binding.
1 reply 0 retweets 1 like -
Replying to @theomn @littlecalculist
1: The point of const to me is to let the user know that the original author INTENDED it to be immutable.
2 replies 0 retweets 0 likes -
2: By saying "always use const and change it whenever it happens to be mutated", you're losing an important signal:
1 reply 0 retweets 0 likes -
3: That the original author considered it questionable to mutate the variable.
1 reply 0 retweets 0 likes -
4: And what are we gaining? In exchange for losing user intent, we gain a minor but noisy piece of metadata ...
1 reply 0 retweets 0 likes -
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?")
1 reply 0 retweets 0 likes -
6: If your functions are too large for it to be quickly analyzable, consider smaller functions.
1 reply 0 retweets 0 likes -
7/7: Your code will be clearer and you won't have given up an important source of user intent.
1 reply 0 retweets 0 likes
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")
1 reply 0 retweets 0 likes -
In rust that kind of change is a public API-breaking change so people are more intentional about it.
1 reply 0 retweets 0 likes - 2 more replies
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.