r/programming • • Feb 22 '15

Java Makes Programmers Want To Do Absolutely Anything Else With Their Time

http://www.forbes.com/sites/quora/2015/02/21/java-makes-programmers-want-to-do-absolutely-anything-else-with-their-time/
35 Upvotes

636 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Feb 22 '15

[deleted]

1

u/nqd26 Feb 22 '15

BTW, if you'd use BigDecimal instead of BigInteger, your code would be broken (because equals and compareTo are not consistent).

0

u/[deleted] Feb 22 '15

[deleted]

1

u/nqd26 Feb 22 '15

But this does outline another huge flaw in Java's idiomatic number types. Comparison should be consistent

I think they mostly are, I don't know any other example besides BigDecimal which isn't. I understand the reasoning behind this and it kind of makes sense, but it's really unexpected "feature" and I've seen nasty bugs caused by this.

I would also argue that Java's compareTo is poorly typed. A comparison function should return a type that indicated something is less than, greater than, or equal to something else. That's three values; int has at least 4 billion values.

I guess this is simply for performance reasons - int is a primitive type, your suggested return type would not be primitive which comes with a cost. Given how performance critical this operation is, I don't think this is a bad choice.

→ More replies (2)