Post #1572215
2026-04-21 16:07 UTC
Replies (2)
-
@Hyperlynx@aus.social 2026-04-22 03:09
@joxean@mastodon.social yes, absolutely! We tend to do it at work, and I'm a big proponent of it. The main reason is that it makes your intent clearer, which makes your code easier to read and understand (especially the first time I see it, in review). When I see `const`, I can immediately eliminate a bunch of possibilities in my mental "what does this code do?" tree. I never have to worry about figuring out what x is going to be assigned or modified. Secondary reason is that it prevents you or others from modifying it accidentally. Mistakes happen, even to the best of us, and if you can completely eliminate a certain class of them for free, why not?
-
@dermojo@hachyderm.io 2026-04-22 15:58
@joxean@mastodon.social We used to, but now we rarely do this at work. Most constants are global, so this eliminates the need for local const. Also, making "intermediate" data const turned out to be more noisy than useful. Our review comments shifted from "these variables could be const" to "this function is too long/complex". The latter helps to prevent accidental modifications.