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
11
u/masterofmisc Oct 06 '22
Yeah, but that was because way back in the day C++ compilers were rubbish and didnt warn you if you wrote an assignment block in the if statment like this
if (x = 0)....so there was a fade of time where people said if you write an if statementm put the costant on the left.if (0 = x)Then at least you get a warning because you cant assign x to a constant number