Re:Const all the things?
by mannykannot on Tuesday January 25, 2022 @10:16AM
(#30072690)
That is an interesting point of view. I am usually reading code in order to understand what it does (or where it goes wrong) without the author being present, where the proper use of const in declarations can save a lot of time.
Almost never, in my experience. During code review, when I see this:
I know quite well the author of that code knows that bar might be changed. There are no questions to ask him here, and no feedback to be given.When I see this:
I've no idea if the author realises that `bar` might be have a different value after `foo()` returns. I have to ask the question "Do you know that `var` might be changed by `foo`? Did you test with the different program states that result in the value that `foo` may assign to `bar`?"In a place where the convention is to use pointers instead of mutable references I never have to ask the question - the code review of the implementation of `foo` would have changed the mutable reference parameter to a pointer parameter.
I read code much more often than I write it. References hurt readability.