gist.github.com/GeePawHill/0be…
Okay, seriously, just join the damned declaration and its initialization into one line.
We're on our way.
that's an example of a single-assign masquerading as two assigns. We can tell this, cuz there are no lines in between the first assign and the second.
int x = chooseX(y)
int chooseX(int y)
{ if(y==17) return 1;
else return 0;
}
If we have a ternary operator, we could use that, too:
x = (y==17) ? 1 : 0;
Got me?
doTheThing(chooseX(y));
the variable x has disappeared.
x <- singleassign
dosomething with x
x <- singleassign
dosomethingelse with x.
that's not two assigns, that's a variable being reused for two different purposes.
Look, kids, if you're not doing geometry in the code -- and usually even if you are -- "x" is a shite name.
In real life, I'd rename x as soon as I saw how it was used, in that doTheThing code.
Thanks, and have a quietly perturbing Wednesday night!