Paul help! wrote:now, to me, it looks like it is the other way around: $a - $b.
Am I missing something here?
NogDog wrote:Frankly, I never remember, so on the rare occasions when I need to do something like that, I try it one way with a small set of test data, and if it comes out in the wrong order, then I swap the 2 variables.
I find it easy to remember by recalling how such a function would be used: comparison with 0 such that foo($x, $y) COMPARISON 0 would mean that $x COMPARISON $y is true, e.g., foo($x, $y) < 0 means that $x is less than $y for whatever "less than" means according to foo.
So, if you want to do the subtraction trick with $a and $b, then it means that to correctly test for $a less than $b, you must make it such that foo($a, $b) < 0. Given $a = 0, $b = 1, it is easy to see that 0 - 1 == -1, so you would return $a - $b.