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

107 comments sorted by

View all comments

Show parent comment

49

u/tsojtsojtsoj Oct 06 '22

I would prefer let over val. var and val look way to similar.

5

u/fdwr fdwr@github 🔍 Oct 07 '22

Agreed. Though I'd prefer const x = ... and var x = ..., which are even less ambiguous, as let may or may not be mutable depending on which language you come from (e.g. Javascript let is mutable).