Hacker News new | ask | show | jobs
by protomolecule 1118 days 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.

1 comments

When 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.
But usually functions are used more than once.

"cascading constness change"

Which is good because invoking code may rely on function being read-only.