Hi,

I read an interesting point recently in an old book on programming...
The author visualises comparisons of values as if they're placed in
their ‘when true’ relative positions on an interval line.

So whereas I'd write ‘x > 10’, he'd write ‘10 < x’ because it's true if
x is to the right of 10:

    ...8  9 10 11 12 13... x

I do this in Python when there's a range, say a half-open interval of
[low, high) with ‘low <= x < high’ because that language allows such
expressions.  In other languages, you often have to break it into two
combined with a logical-and: ‘low <= x && x < high’.  But otherwise
I tend to put the variable that's more in focus on the left side of
a comparison.

A consequence is he never uses > and >= as the operands to his
comparisons are always ordered left to right.

(This is quite separate to putting constants on the left when testing
 equality to detect accidental use of assignment instead of comparison:
 ‘10 == x’.  That just remains weird and has dropped out of fashion as
 compilers now warn of ‘x = 10’ as a test.)

-- 
Cheers, Ralph.

-- 
  Next meeting: Online, Jitsi, Tuesday, 2025-08-05 20:00
  Check to whom you are replying
  Meetings, mailing list, IRC, ...  https://dorset.lug.org.uk
  New thread, don't hijack:  mailto:dorset@mailman.lug.org.uk

Reply via email to