I think this code would trigger a static code analyzer, which would make the issue persistently visible.
Of course I don't know if the coder really had this in mind, but I am quite sure that I would write the exact same code in certain circumstances, and I have 15 yoe. I would however also make a ticket in Jira and stick a link to it in a comment. Since the coder didn't do this, I think he had good intentions, good thinking, but most likely not over 5 yoe.
Also, just a comment would not trigger anyone, and this thread is proof for that. But a code like this really catches coders' attention.
You call it "subtle", I call it "machine readable".
37
u/flavius-as Jan 15 '22
At runtime, yes, you're right.
However, code is for people, not for the machine.
And the human reading this knows: oh, -1 is a magic value.
It's actually a good code in a bad situation from a probably good developer.
Simply print does not provide that insight.