4 ms·
I do exactly this in my own code, for one-sided bounds like "if (0 <= x)" as well as for two-sided bounds like "if (0 <= i && i < length)". But when collaborat
by garethrees 11y ago
I do exactly this in my own code, for one-sided bounds like "if (0 <= x)" as well as for two-sided bounds like "if (0 <= i && i < length)".
But when collaborating with other programmers, I follow the majority style. There are lots of programmers who prefer to write comparisons with the varying item on the left and the constant item on the right, and "varying item is on the left" is just as valuable a hint to them as "lower item is on the left (if expression is true)" is to me.
So I wouldn't elevate a personal stylistic preference to a rule: this will lead to pointless arguments. Writing code that's clear to all the programmers on a project should be the goal.