News for hackers. Stuff that matters.
Re:`three = 1` in the Linux sourcecode (2014) by scotty79 on Tuesday March 09, 2021 @06:41AM (#26397889)
Not really. Nobody sane would think other sane developer with any expeirience would call a simple variable according to what it initially contains. You'd expect either name related to what is the meaning of the contents, or meaningless name.
Re:`three = 1` in the Linux sourcecode (2014) by oji0hub on Tuesday March 09, 2021 @06:46AM (#26397913)
People make typos and simple mistakes all the time, regardless of experience.
Re:`three = 1` in the Linux sourcecode (2014) by scotty79 on Tuesday March 09, 2021 @08:47AM (#26398684)
True. But the intention of writing

    int three = 3;
is insane.

I would never ascribe to previous programmer (unless he just learned what variables are) the intention of creating variable (not even constant, which wouldn't make it any better) named 'three' and assigning actual value 3 to it.

Re:`three = 1` in the Linux sourcecode (2014) by forgottenlogin9 on Tuesday March 09, 2021 @09:13AM (#26398929)
If that is insane, you may not have issue with this specific line but you surely have issue with the 2 “insane” lines that follow it?
Re:`three = 1` in the Linux sourcecode (2014) by esrauch on Tuesday March 09, 2021 @09:23AM (#26399013)
All three lines would be "insane" if the variables weren't mutated. As in a variable named "three" is insane if it solely contains either of the values 1 or 3.

When it contains other values it is still subpar variable naming.

Re:`three = 1` in the Linux sourcecode (2014) by scotty79 on Tuesday March 09, 2021 @10:49AM (#26399935)
If something looks insane, but probablu sane person made it and it works then that's usually good indicator that you are missing part of the picture and should look around. It still might be bad, but probably not insane.
Re:`three = 1` in the Linux sourcecode (2014) by Guthur on Tuesday March 09, 2021 @06:50AM (#26397941)
+1 seen it so many times, often times from some cut and paste heavy refactor, one is more or less going on autopilot just moving substrings around and then bam. Review process hopefully catches it, when it is a bug, and potentially when the semantics are unclear...
Re:`three = 1` in the Linux sourcecode (2014) by tremon on Tuesday March 09, 2021 @09:16AM (#26398951)
When

  unsigned three = 1;
is accompanied by

  unsigned five = 5;
  unsigned seven = 7;
what would be the sane conclusion?
Re:`three = 1` in the Linux sourcecode (2014) by klyrs on Tuesday March 09, 2021 @01:21PM (#26401769)
The reasonable conclusion is that you should read the surrounding context and try to understand what these variables are used for. The purpose of code review is to understand the code enough that you can spot real bugs; I try to avoid flagging surface-level stuff unless it's really important. IMO, this is a borderline case due to the very clear comment (which is a bit too far away).
Re:`three = 1` in the Linux sourcecode (2014) by jfengel on Tuesday March 09, 2021 @01:51PM (#26402239)
And then, having located that comment, try to rename the variable to something more meaningful. Even gap1, gap2, and gap3 would be more informative.
Re:`three = 1` in the Linux sourcecode (2014) by klyrs on Tuesday March 09, 2021 @01:58PM (#26402355)
We have a difference of opinion here. I lean away from bikeshedding in favor of finding more substantive issues. I'm also an old-timer and I'd call this a 3, on a scale from 1 (easily readable code) to 10 (a suitable IOCCC entry)
Re:`three = 1` in the Linux sourcecode (2014) by jfengel on Tuesday March 09, 2021 @02:06PM (#26402490)
It's also true that unless I had a specific mandate to touch that code, I wouldn't. If nothing else it confuses the commit history, obscuring what I was actually in there to do.

But if it were my job to touch these lines of code, I would want to leave them better than I found them.

Re:`three = 1` in the Linux sourcecode (2014) by scotty79 on Tuesday March 09, 2021 @10:58AM (#26400052)
That there are some entities (maybe ordered, maybe related to numbers three, five and seven in some way) and there are some values associated with those entities, two of which (accidentally or not) need to be initially set to corresponding number, but the third one possibly not, but better look around in the comments or code to understand and make sure the code is correct.

Then maybe leave a comment right after `= 1;` why this variable shouldn't be initialized with 3 that would clear up confusion for you if it was there.

Re:`three = 1` in the Linux sourcecode (2014) by marcosdumay on Tuesday March 09, 2021 @10:11AM (#26399497)
That the code was edited more than once on its lifetime, and in one of those times (not the last one), by someone with pretty bad naming habits.
Re:`three = 1` in the Linux sourcecode (2014) by megous on Tuesday March 09, 2021 @10:02AM (#26399434)
These are variables that will change anyway, so the initial values are probably not that relevant to their name?
Re:`three = 1` in the Linux sourcecode (2014) by magicalhippo on Tuesday March 09, 2021 @12:38PM (#26401235)
In which case the names should be cnt0, cnt1, cnt2 or something along those lines.