Completely agree with this point.
FWIW, I consider #1 to be the default option that we should go with unless there is something clearly better. We have had this behavior for years now and (as you say) it is highly precedented in other languages. I agree it is suboptimal, but not enough to be worth heroic solutions given where we are.
I haven't carefully considered this, but what about a variant of this:
- Do not change any existing behavior.
- Introduce an new/additive
<=>
operator, returning less/greater/equal/unordered, which is (by default) implemented in terms of the<
and==
operators for a type. Floating point types would override this default implementation with the obvious impl.
This solution is nice because:
-
It does not affect source or ABI compatibility.
-
sort
and specific other algorithms could (optionally) be changed to use this, incrementally fixing a bug for FP types and possibly making those algorithms more efficient. If done in time for Swift 5, this operator could might even be able to be added as a requirement forComparable
types. -
It is additive, so it can be done at any time.
-
For users that hit surprising behavior in practice, e.g. your
contains
example, they can use this (along the a closure predicate) to get the behavior they want.
Have you considered an approach like this?
-Chris