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]

0

u/[deleted] Feb 22 '15

[deleted]

1

u/TomRK1089 Feb 22 '15

Perhaps you should brush up on your fundamentals then. If you want less than or equal to, you write

x.compareTo(z) <= 0

compareTo is defined as any negative integer being less than, not just -1. So, it's your own fault your code is verbose, and wrong, too.

0

u/[deleted] Feb 22 '15

[deleted]

1

u/TomRK1089 Feb 23 '15

Implemented from Comparable which specifies that it should return "a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object." It's really BigInteger which is at fault here for over-specifying in its documentation how its particular implementation works.

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.

0

u/[deleted] Feb 22 '15

[deleted]

1

u/nqd26 Feb 22 '15

I suspect it may be a much lower cost than the cost of Java method invocation.

Well, in this case it doesn't really make sense to allow creating new instances of the type - you just have three constant instances - LT, EQ, GT. Cost to use this is quite small (but non-zero), it's just dereferencing one pointer. Whether this is more or less than method call depends on whether call is inlined. Compiler/JVM could treat this in a special manner and might be able to optimize the cost to 0 ... (e.g. in a similer manner how GHC does it)

1

u/geodel Feb 22 '15 edited Feb 22 '15

I am not trying exaggerate but it is indeed considered clean and precise as it is not using elaborately designed generic framework of the main application which is like 2 dozen classes 1000s of lines of code to open and manage http / jms connections and this is with using all apache and what not jar libraries to provide core functionality.

I should talk less as I am already considered bad developer for calling out shortcomings of framework as I do not see big picture.

Java is way of life here where everything is planned for decades but craps out on first production load.