page =
url = https://quuxplusone.github.io/blog
arthur o'dwyer – stuff mostly about c++
antipatterns c++-style pitfalls
Last week someone posted a /r/cpp thread titled “Declaring all variables local to a function as const” :
Ok, so I’m an old-school C++ programmer using the language now since the early ’90s. I’m a fan of const-correctness for function and member declarations, parameters, and the like. Where, I believe, it actually matters.
Now we have a team member who has jumped on the “everything is const” bandwagon. Every code review includes dozens of lines of local function variables now declared
that litter the review.
Intellectually, I understand the (what I consider mostly insignificant) arguments in favor of this practice, but in nearly 30 years I have never had a bug introduced into my code because a local function variable was mutable when I didn’t expect it. It does nothing for me to aid in code analysis or tracking. It has at most a tiny impact on performance.
Maybe I’m just an old dog finally unable to learn a new trick. So, on this fine Wednesday, who’s up for a religious war? What are y’all doing?
TLDR: I’m not putting
on all the things, either.