News for hackers. Stuff that matters.
Re:Const all the things? by tsimionescu on Monday January 24, 2022 @05:14AM (#30055614)
> Like, what if they are being modified if that's the called function has to do anyways ?

The idea is that you have some code like this:

  x = some_func();
  do_something(x);
  if x == 0 {
    do_something_else();
  }
You're trying to track down why do_something_else() wasn't called, let's say. Do you have to look at the definition of do_something()? If your coding standards say "no non-const references", then no. If do_something() was modifying x, it would have looked differently, so you can ignore it.
Re:Const all the things? by gpderetta on Monday January 24, 2022 @09:31AM (#30058006)
To stay on topic, if x was declared const, you wouldn't have to guess. The compiler would tell you.
Re:Const all the things? by lelanthran on Monday January 24, 2022 @11:50AM (#30060204)
> To stay on topic, if x was declared const, you wouldn't have to guess. The compiler would tell you.

Frequently it can't be declared constant, because it is being changed in that scope as it runs.

Re:Const all the things? by tsimionescu on Monday January 24, 2022 @04:46PM (#30064516)
This was a discussion about passing out (or inout) parameters as `T&` vs `T*`. By definition, these parameters can't be const, so const is irrelevant to this thread.
Re:Const all the things? by gpderetta on Sunday January 30, 2022 @09:46AM (#30137610)
Good point.
Re:Const all the things? by jcelerier on Monday January 24, 2022 @06:26AM (#30056221)
> You're trying to track down why do_something_else() wasn't called, let's say

Then I put a breakpoint at that line and hit f5 and don't try to guess what may or may not happen because in the end that's the only way to know what actually happens

Re:Const all the things? by lelanthran on Monday January 24, 2022 @07:08AM (#30056639)
> Then I put a breakpoint at that line and hit f5 and don't try to guess what may or may not happen because in the end that's the only way to know what actually happens

There's no need to guess if the parameter is passed by value only. When pointers are used visual inspection alone is enough to ensure that the reader knows what he value of the argument is after the callee returns.

I said that it's easier to read when pointers are used, and you propose stepping through the code as an alternative. Surely you see my point now?

Re:Const all the things? by tsimionescu on Monday January 24, 2022 @07:00AM (#30056567)
You can't always reproduce a bug. Also, do you Step Over do_something(x) or Step Into? You definitely step into if it's do_something(&x).