←back to thread

504 points azhenley | 1 comments | | HN request time: 0.207s | source
Show context
loeg ◴[] No.45768135[source]
Yeah, I also wish it was the default. But it's a little too verbose to just sprinkle on every variable in C++. Alas. Rust gets this right, but I'm stuck with C++ at work.
replies(2): >>45771522 #>>45773574 #
maleldil ◴[] No.45773574[source]
> 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.

replies(1): >>45777172 #
loeg ◴[] No.45777172[source]
Const annotations are worth it for methods and APIs, but not most local variables.
replies(1): >>45778787 #
maleldil ◴[] No.45778787[source]
I'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.
replies(1): >>45783622 #
1. loeg ◴[] No.45783622[source]
Yeah, I think it's a great default, and Rust got that right. It's just too noisy in C++ as the non-default.