4 ms·
> But it's a little too verbose to just sprinkle on every variable in C++ It's worth it, though. Every variable that isn't mutated should be const. Every param
by maleldil 1y ago
> But it's a little too verbose to just sprinkle on every variable in C++
It's worth it, though. Every variable that isn't mutated should be const. Every parameter not mutated should be const, and so should every method that doesn't mutate any fields. The mutable keyword should be banned.
- loeg 1y agoConst annotations are worth it for methods and APIs, but not most local variables.
- maleldil 1y agoI'd argue that it is. Use const by default, so it's obvious to the reader if something is mutated or not. It's easier to read code when you don't have to worry about how values may change over time. This is why Rust made the right choice.
- loeg 1y agoYeah, I think it's a great default, and Rust got that right. It's just too noisy in C++ as the non-default.