Hacker News new | ask | show | jobs
by 5hoom 4434 days ago
That's one thing I've noticed with my C++ code lately is that I'm writing const absolutely everywhere. Having mutability where you need it is awesome but it is interesting to see languages like Rust where immutability is the default.
1 comments

I have done a bit of this too. The main downside in C++ is that you end up writing a few more ternary operators than you otherwise may have. But it is nice to be able to look at the first assignment of a variable and know it is the only one.
Yeah it kind of feels dirty having all these mutable variables around after doing any functional programming at all.

I've found using const a lot also goes hand-in-hand with raii. If a member of a class is const it must be initialized in the constructor, and it just seems to make me code a bit more "hygienically".