4 ms·
"It adds mental overhead." To me `const` removes mental overhead -- if I pass a const object somewhere, I can be sure it doesn't get changed. I don't need to i
by protomolecule 3y ago
"It adds mental overhead."
To me `const` removes mental overhead -- if I pass a const object somewhere, I can be sure it doesn't get changed. I don't need to inspect the code to make sure it doesn't call any methods that modify the object or trust a probably outdated comment or documentation.
- rightbyte 3y agoWhen you are using the function, ye. Not when you are writing it. And if you someday want to change a const method to non-const you could have a cascading constness change all over the place.
- protomolecule 3y agoBut usually functions are used more than once. "cascading constness change" Which is good because invoking code may rely on function being read-only.