Why Java Is Not My Favourite Programming Language

Ahem.

Java has four different “kinds” of types. Up until Tiger, it had these three:

  1. Primitive types: longs, shorts, booleans, ints, outs, whatever. They map more or less to machine types.
  2. Classes, which are the primary mechanism for extending the language.
  3. Arrays, which are this weird hybrid type that was introduced to make it easy to port C and C++ code to Java. But you can’t make arrays immutable, and you can’t subclass them, and there’s only modest syntactic support for them, and reflecting on them is painful.

The problem, of course, with having different types of types is that all of the code you write, now and forever, has to be prepared to deal with each type-type differently. So you get interfaces like this lovely one. Scroll down to the Method Summary, and looky looky, there are 76 actual methods in the class, but only 10 distinct pieces of functionality.

Just to make things worse, Java 5 added a new kind of type, called an enum. They’re sort of like C enumerations, but they can also have methods. Which makes them sort of like Java classes, but you can’t instantiate them, and you can’t have one enum type inherit from another enum type, so you can’t have polymorphic methods, nor can you declare an enumeration heirarchy. So they’re not really like classes at all.

– Steve Yegge, The Next Big Thing (lightly edited for brevity).

Case closed.

About these ads

15 responses to “Why Java Is Not My Favourite Programming Language

  1. And Strings have overloaded operators, but programmers cannot create their own classes with overloaded operators. Then there is autoboxing and having two types for the same kinds of values.

  2. Pretty cheap shot, not very Java-specific (most of it applies tho a vast number of non-pure OOPLs that offer a mix of objects, primitive types and arrays, including C++, C#… – with various degrees of success to hide the ugliness, usually through autoboxing – so an int walks and quacks like an object but you still can’t inherit it and polymorphically overload its methods, etc.)

    Oh, and you CAN have subclasses and polymorphic methods on enums. It’s a restricted facility but pretty neat. It seems Steve didn’t do his homework, and as you blindly quoted this, you don’t really master Java either.

    It’s interesting too that, differently from other languages from this series, you were not able to quote a piece of specification (JLS) or a first-class authority on Java language design (Steve is a smart and well-known hacker, but certainly not in the league of Bracha, Bloch, Gafter, Joy, Gosling, etc.).

  3. Osvaldo, you’re right that for the Java whinge I didn’t quote official documentation; that’s because I’ve not read it. As you rightly surmise, I have not mastered Java; far from it. I’m only a visitor in the Kingdom Of Nouns. I’ve used, and read about, the other languages in this series much more extensively than Java, but it seemed to me that leaving Java out completely wouldn’t be right.

  4. Mike: Fair enough. But the problem of making fun|criticism of a language that you don’t master, is that you may not find its really ugly bits (and the really authoritative texts that expose it). And as a good Java advocate, I won’t provide you the links. ;-)

    But frankly, there are no major blunders in the Java language: at least nothing remotely in the level of the stuff you blogged for other langs. There are some important warts in obvious areas (generics), but these are mostly by-design tradeoffs, so they have their elegant side and their advantages and defenses. The real language design screw-ups are those that happen without explicit planning, or due to sheer design incompetence, or to extreme tradeoffs (like C++’s mountainous issues related to C compatibility). I can remember only very minor issues, like Java’s package-private visibility level. A bigger issue was the original Memory Model, but that was fixed on J2SE5. OTOH, there are tons of major blunders in Java’s standard APIs, remarkably earlier ones – and these are very important as Java is one of these languages with a philosophy of a small language kernel surrounded by vast frameworks, so whenever those fail, and a complete fix is forever impossible due to backwards compatibility, it’s just as bad as a syntax screwup in a “big language” like C++ or Perl.

  5. Steven Pennebaker

    No, let’s not leave Java out. Thing is, the beauty of the C, Javascript, Ruby and Perl examples is that they’re bug traps, places where the language let’s you or encourages you to make mistakes that will cost you later. Even better, these paths are main roads, not obscure byways. Java and Pascal (if I remember correctly, it’s been a while since I did any Pascal) are designed to prevent dumb errors and typos from sinking your boat without some bad design on your part. At least no example comes immediately to mind, somebody prove me wrong!

    Ha, if failure to live up to a philosophical aesthetic is a crime, the best language out there is going to be “anything goes” Perl, LOL.

  6. Osvaldo Pinali Doederlein boldly asserted that “there are no major blunders in the Java language”. Surprisingly enough, I do more or less agree with that. I think that is a nice consequence of Java’s lack of ambition: it was pretty much deliberately designed as C++ Without The Compromises To Keep It Binary Compatible With C, and it did a good job of learning from C’s and C++’s mistakes, to produce a language that is much smaller and more pleasant than C++ and perhaps on a par with C.

    My main issue with Java is actually much more mundane than any specific flaw … but since I have a fair bit to say on that subject, I’ll save it for the next post. Hope that’s OK.

  7. Pingback: So what actually is my favourite programming language? « The Reinvigorated Programmer

  8. What the hell? Where do I even start with this idiotic blog?

    You haven’t read the Java documentation, haven’t mastered the language…but you pull one quote out of your a** and it’s “case closed”?

    Oh what the hell, I guess you now know about as much as any other author of computer books, so maybe you should pitch a manuscript on Java to O’Reilly or somebody.

    Guys like you make me hate the internet. Seriously.

  9. foo: it should be quite obvious that anything titled ‘Why {X} Is Not My Favourite Programming Language’ is written at least slightly tongue-in-cheek. Have you really not read the original?

    (Are you going to include Pascal in this list, Mike? ‘cos you could just quote virtually anything from the original Kernighan paper :) )

  10. Hi, Nix, thanks for that your flood of comments — it’s great to get your perspective on so much of what I have written all at once. You talk a lot of sense.

    I actually read the original Why Pascal is not … in a hardcopy that Kernighan himself sent to me, long long ago. Stupidly, I don’t know where it is now — one more reason why I really, really need to tidy my office up.

    As you’ll have seen now, the short Why X Is not … series is now over, and I didn’t cover Pascal. It just didn’t seem worth complaining about a language that has so few serious advocates these days anyway. The six that I mentioned (C++, Perl, JavaScript, C, Ruby, Java) are languages that are in wide us today for solving realistic problems, and that also (with the possibly exception of JavaScript) have substantial communities of people who genuinely love them.

  11. I dunno. JS has enough lovable components that I think you could get a nice language out of it if you attacked it with pruning shears. It does, very occasionally, get used outside the web context (though the only example that springs to mind is the AI and automation engine for oolite).

    I think your choice of languages was a good one (Python could have done with being in there too, but obviously you aren’t going to dare criticise a language that you haven’t used recently after the Java fiasco).

    (If I had to find one thing to flame about Python, it would be the long period when Python 2 had *two* ways to declare classes with different semantics, though one was admittedly deprecated. Even C++ never did that.)

  12. As a matter of fact, the main reason I left Python out was because I’d already done Perl and Ruby, and I feel that those three languages have enough in common and live in sufficiently close to the same space that doing the third was redundant.

    I actually learned most of my JavaScript from Douglas Crockford’s excellent book JavaScript: the Good Parts, the thesis of which is indeed that there is a nice language in there. Unfortunately, I think the environments that it runs in are far more crippling than the language’s real deficiencies, even the single global namespace.

    Finally, I am not that inexperienced in Java: a while back I wrote and released an open-source parser for the standard query language CQL, which you can get at http://zing.z3950.org/cql/java/ — I’m not saying it’s a huge and significant piece of code, but it is at least more than a toy (and deployed in several production systems by several different companies).

  13. Java is a ridiculous language because of all the redundancy and twisting you have to do to get around its insane typing.

    To go back to an example from the Kingdom of Nouns:

    steve.takeoutgarbage().

    In a superior language such as Ruby you can make a Garbage module complete with implementation and add it to any class via mixins.

    In Java you either have to make an abstract class which is a bad idea, or have a Garbage interface which is slightly better.

    Problem is that EVERY class that you want to give the ability to take out the garbage you have to duplicate the code. To make matters worse the same object is now likely to have several references of several types floating all over the place. BAD BAD BAD BAD

    Ruby, like Java is strongly typed, and arguably even more strongly typed. Yet, it does not have all the headaches and requires no contortions to get things to work.

    Why?

    Because the creators of Ruby understand what OOP really means. Hint: messaging.

    I doubt Java will ever have acceptable closure support because of typing, but mostly because of checked exceptions, another terrible idea that adds verbosity with little gain.

    In Java patterns exist to overcome its many limitations. In other languages they are simply a guide and not really necessary. The thought of someone using factories in ruby is quite a funny one.

  14. “But frankly, there are no major blunders in the Java language: at least nothing remotely in the level of the stuff you blogged for other langs.”

    Is this a joke?

    No one can look at the mess that Java produces, yes even by its “masters” and not snicker.

  15. Nice trolling, @qwerty, but too bad that you couldn’t present anything more concrete and articulate than your poor generic attack to static-typed languages (I don’t see much Java-specific content there).

    Oh and don’t embarrass yourself with claims like “Ruby is arguably more strong-typed than Java” unless you know what you’re talking about and you can actually follow up with some real argument to back the ‘arguably’. I’m waiting… how exactly is Ruby “more strong-typed than Java”?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s