Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask HN: Does anyone else not use greater than?
2 points by windows2020 on Oct 6, 2022 | hide | past | favorite | 8 comments
Does anyone else not use > and >= and stick with only < and <=? If so, what was the inspiration?


I do (er, don't) do that, mostly, just so the arguments are size-increasing

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


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.


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.


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


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.


It should rhyme:

    if (x > y)
        x = y;


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


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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: