Java and Primitive Types… latest round

java_logoThis point surfaces once in a while… I guess it’s time for a new round: Would Java Be Better Off Without Primitives?

I became aware of this issue a long long time ago, by reading this excellent IBM paper: Primitive Types Considered Harmful (download available as PostScript only). It’s quite outdated now because at the time (1998), there were no such things as Collections and auto(un)boxing, but the roots of evil were already there. And it’s still a good read that I recommend to any serious Java programmer.

This paper also included a proposal that could have been almost painlessly integrated into the JVM, and would have allowed immediate types similar to what exists in SmallTalk. Obviously this proposal didn’t make its way into Java.

Now I wonder what good it does to argue about this once again. After reading about this, I have come to the conclusion that:

  • primitive types were originally introduced into the Java language for a wrong reason: performance. We know today that the performance gain was not worth the confusion and lack of consistency that resulted from this choice. The introduction of auto(un)boxing only added to the confusion, just to save a few lines of code.
  • primitive types will not go away. The Java language has reached a point where it has too much inertia to even think of introducing such a radical change. I believe that if closures ever make their way into Java it will be the last significant change.
  • it’s alright this way. Now that everyone has learned to use primitive and wrapper types, now that auto(un)boxing, however awkward, is there, what would be the real benefit, other than to satisfy a few purists? Java is not a pure OO language. So what? If you want to do pure OO, do SmallTalk… The strength of Java is not there, it’s in its ubiquitous presence, its profusion of libraries and tools, its ease to find as a skill, etc.

So we can continue to make mental exercises and debate on how Java could be altered to eliminate the need for primitive types, or we can accept the situation and do with it. I’m not saying the former is not interesting, in the contrary… but I’ve chosen my side.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.