HACKER Q&A
📣 windows2020

Does anyone else not use greater than?


Does anyone else not use > and >= and stick with only < and <=? If so, what was the inspiration?


  👤 jjgreen Accepted Answer ✓
I do (er, don't) do that, mostly, just so the arguments are size-increasing

    if ((0 <= x) && (x < 10)) { ...

👤 dave4420
I do that.

I visualise the variables as being on the number line. If they’re the way round that they appear in the code, then the condition is true.

Unfortunately my code reviewers tend not to like it when I write constant < variable.


👤 grandmaa
I like to be fair to all the comparators and use the greater than, equal to or less than operator:

    <=>
Admittedly it's only good for checking that a value isn't NaN.

👤 mac3n
I always use <, <=, for consistency and to make the ordering clear

in mathematical notation, 0 <= i < n is sometimes used for summations where i ranges from 0 through n-1


👤 joshxyz
the inspiration is the number line, small numbers at the left, larger numbers at the right, because we write left to right, and the sequence is 1 2 3 4..

which is why you always want the larger ones on the right.


👤 ffhhj
It should rhyme:

    if (x > y)
        x = y;

👤 jstx1
Probably the other way around, I’m more likely to use > and >=.

👤 muzani
I use `x > 0` for comparisons with 0 and negative