Hello,
I'm pretty sure this must have come up a few times now, but
I was unable to find a discussion anywhere, so here goes:

The `if (object.compareTo(other) > 0)` construct for Comparables,
while it works, is an annoyance to readers, and I often have to
do a double-take when seeing it, to make sure it says what I think
it says.

Did we ever consider adding human-friendly default methods
to Comparable like e.g. these (names obviously subject to change):

```java
public default boolean lessThan(T other) {
    return compareTo(other) < 0;
}

public default boolean lessThanOrEqual(T other) {
    return compareTo(other) <= 0;
}

public default boolean comparesEqual(T other) {
    return compareTo(other) == 0;
}

public default boolean greaterThanOrEqual(T other) {
    return compareTo(other) >= 0;
}

public default boolean greaterThan(T other) {
    return compareTo(other) > 0;
}
```

These are pure human convenience methods to make the code easier
to read, we do not *need* them. Still, I absolutely personally
think the simplification they'd provide is worth the cost.

Are there any problems with the proposed methods that prevent them
to ever appear? Wise from the CharSequence.isEmpty() incompatibility
(https://stuartmarks.wordpress.com/2020/09/22/incompatibilities-with-jdk-15-charsequence-isempty/)
I looked at common libraries to look up potential matches, but
did not find any. The closest thing I found was AssertJ with
isGreaterThan(), and some greaterThan() methods with two or more
parameters in some obscure libraries. Now, I'm sure there *will*
be matches somewhere, and this is a risk that needs to be assessed.
Or was it simply a "meh" feature not worth the hassle?

Thank you,
PJ

P.S. I'm not a native English speaker, so the method names are
up for a potential discussion if we agree they'd make our lives
easier. I can imagine something like `comparesLessThan` or similar
variations, too.

P.P.S. The `Comparator` interface does also come into mind as it
could take similar methods, but I did not see a clear naming
pattern there. I'm open to suggestions.

Reply via email to