Interesting “bloated java” Article

An interesting read over at http://www.bluej.org/mrt/?p=34 titled “Can Java be saved from death by feature bloat?”

There are some points that i do agree with, others that i don’t. I do think in general that java is getting bloated but i don’t agree with some of the details. But I’ve used a lot of languages and some languages are better suited for some things than others, and so you have to take the good with the bad.

Not everything is all bad however, java is only one language on the JVM, and Sun is finally pushing that seriously. JRuby is looking good and i like what I’m reading about it. But i prefer python and so would love the same support to go to Jython. These days, whenever i have a choice i go with Python.

What was really interesting about that post was the following:

boolean result = !(i < j) && !(i > j) && !(i == j);

Assume i and j are numbers. What we are saying in this expression is quite simple: i is not less than j, i is not greater than j, and i is not equal to j. Now the question: Can this ever be true?

Take a moment to think about it.

I said no. And if you did too, then you’d be right. But…..

So logically, one would say no. This can’t ever be true. But….
Going by our intuition (and everything we knew up to Java 1.4), the answer would be no. Since Java 5, however, it can be true. Here is how:

Integer i = new Integer(13);
Integer j = new Integer(13);
boolean result = !(i < j) && !(i > j) && !(i == j);

With this definition, result will be true. This is because the < and > operators auto-unbox, but the == operator does not and does object reference equality instead. It is counter-intuitive, completely useless for anything sensible in practice, and a potential for error.

You see, i knew about boxing and un-boxing and thought that it was a welcome addition to java 1.5(in the older days, we had to code around it) but i didn’t know about == operator with un-boxing. Its true that this looks more like those trick programming puzzles that have their answers buried deep within the language’s specification. But i can see how an error like this can cause a lot of headaches deep within the folds of a big application.

I think that its stupid. Programmers shouldn’t waste their time and their gray matter knowing things like this….

One thought on “Interesting “bloated java” Article

  1. athomas

    I was spoiled for awhile when I did Python for over 4 years. Then I got another job doing Java. It was horrible. Had to write far too many more lines of code to accomplish the same tasks. Awful

Comments are closed.