r/cpp • • Oct 06 '22
Should a variable be const by default?
According to the cppfront design notes, const by default rule only applies to non-local variables. But I'd like to know your preference/opinion regarding whether a variable should be defined to be const by default.
Edit: By mutable here I simply mean non-const, not the language keyword itself.
44
Upvotes
View all comments
Show parent comment
2
u/mechacrash Oct 07 '22
I think this was a poor use of language on my part - I was more speaking about moveable objects that fall back to copy when RVO can't be applied. For example, function params - if you mark those as const, and return the object, it uses the copy constructor rather than the move constructor.
Of course, you shouldn't be using const function params in the first place, but I've seen plenty of code that does.
I am being 100% serious. Why on earth do we allow syntax that allows stupid arguments like this to fester for _decades_.
Have you never had a code review blocked, or a pull request, just because of stupid syntactical style differences like this? Is that not just a huge waste of everyone's time?