Today, I realized that !=
and <>
can be different.
Of course, they are equivalent in the ideal domain, but we live in a polymorphic world where two values can be incomparable with each other.
For example, 1
, a number, is incomparable to "Hello"
, a string of text.
This relation is mathematically known as a Partial Ordering.
Arguably, "Hello"
doesn’t literally equal one, which we can denote as "Hello" ≠ 1
.
On the other hand, "Hello" ≶ 1
doesn’t quite hold.
Their mutual incomparability means that neither is less or greather than the other; it would instead be "Hello" ≸ 1
.
That said, we write !=
and <>
, especially in coding, not ≠
and ≶
.
And, depending on the coding language, comparison operators < ≤ = ≥ >
might error or return null/nil for incomparable values.
By set logic, Partial Ordering happily defines false for all five incomparable comparisons, since it has “or incomparable” versions for them: ≱ ≯ ≸ ≮ ≰
.
The spaceship operator <=>
boolean-wise matches the ⋚
comparison in Ruby, thanks to everything but false
and nil
being truthful in Ruby, and Ruby’s <=>
results in nil for incomparables.
Are there any other coïncidences? Shall we create more?