A calm and rational discussion of Java

In the past I believe I may have said that Java was god-awful. I was mistaken. Java is far more evil than any god. Java sucks like the black, empty vacuum-void of nothing that existed before time began.

I'm tasked with maintaining and updating some Java code at work. Today I wandered in to work in a chipper mood. The sun was shining, the birds were singing, life was good. Oblivious, I sat at my computer and fired up Eclipse. 20 minutes later it opened and I was looking at some Java code.

Events played themselves out like they usually do As Java flowed across my computer screen, at first it was a slight twinge in the back of my mind that something was wrong. All too quickly that twinge became a dull sort of deep-seated pain. As the minutes passed, my good mood drained from me like my life-blood draining from an open wound. Joy was replaced with horror at the programming atrocities being committed before my eyes. I'm not exaggerating to say that a few times I've looked at my screen wide-eyed, mouth agape, as involuntary mad laughter escaped me.

Whatever my many other faults, I'm pretty fast at reading code and understanding it. Still it took me over an hour today just to locate the place I needed to add five lines of code to get my job done. Generally I'll start at the top of some 20-level-deep hierarchy of classes and interfaces and abstract classes, and work my way down into it until I look back and realize I have no idea where I came from or what I'm even looking for any longer. You see, public abstract class com.someDomain.project.client.model.table.AbstractEditableTableModel, which extends AbstractTableModel and implements EditableTableModel, which itself is a superclass of GenericTableDataModel and MultiTableDataModel, may contain the stub of a method I have a vague notion I may want to look at someday, but the fun thing about Java is that I get to search the whole hierarchy of imaginary insubstantiatable classes top to bottom until I find the overridding method that really implements the logic I need to see. Then I get to re-search the whole tree to find all the methods that method calls, along with the many separate trees of classes of all the objects the first class uses.

The code I'm dealing with is 210 classes and interfaces worth of Java that does little more than fetch some data from a database and display it in a GUI in a couple of grids. Those 210 classes of course extend and implement many bits and pieces of standard classes from the Java's standard library, meaning the number of classes I really have to deal with is far higher. And most of them DON'T DO ANYTHING.

Most of this code is completely without comments of course, and important variables are named things like s and data. And methods have names like good old actionPerformed; so if the program, you know, performs any actions, I guess I'm covered.

But I shouldn't say it's entirely without documentation. Here's one method along with its documentation.

// used to propogate [sic] privilges [sic] down to the lowest node
public void pushPrivileges()
{
    int myPrivileges = getPrivileges();
    Iterator i = tables.keySet().iterator();
    while( i.hasNext() )
    {
        tableModel tbl = tables.get(i.next());
        tbl.addPrivileges(myPrivileges);
        tbl.pushPrivileges();
    }
}

This is one of the hundreds of boilerplate methods in the code I'm dealing with. I often wonder what proportion of code in Java actually directly works to solve your problem, and what proportion just flips buttons and turns knobs on hundreds of objects which in turn flip buttons and turn knobs on other objects, most of which have no need to exist, while Java spins its wheels in the mud. The above method would be one or two lines of straightforward Lisp or Ruby code, if this method even had a need to exist. Java is much like a 100-armed monster, who will put 3 of those arms to work to solve your problem if you very carefully tell it how to use the other 97 arms to masturbate itself.

The highpoint of my day though was finding a method called "isHasDeletePrivilege". Only Java could inspire such madness in a programmer. I very barely managed to keep myself from right-clicking in Eclipse, selecting refactor => rename and typing canHasDeletePrivilege. If you try to read Java code from the perspective of a group of retarded pseudo-sapient cats living on the internet, it actually makes a bit more sense.

The worst thing about Java is that it actually just barely can be used to solve most problems, which only continues to encourage people to use it.

Tags: , ,

8 Responses to “A calm and rational discussion of Java”

  1. Quoth Zeth:

    This post popped up in my RSS reader in the early hours of the morning here in the UK, so I was going to bookmark it. However, after the first two sentences I made it my home page. I hate Java and I hate all the people that keep throwing it into my face as a solution to a problem. Add Java to a problem, you now have two problems.

  2. Quoth Jeremy:

    Java has its faults, yes. But to write truly bad code you need one of two things:

    1) A programmer who doesn't have a clue
    2) a code generator.

    Sounds like your boilerplate code was generated that way.

    I think you'll find that if you actually spent the time learning swing and the java object model you'd find it a lot easier to navigate that codebase. 210 classes is small time stuff if the project is correctly structured.

    Make no mistake, there are some parts of Java I loathe with the heat of a million suns. But the language itself is actually quite good, if you know your way around it.

    J

  3. Quoth Hollow:

    One important thing to note here is, that it really is the java *language* which sucks, not the java *virtual machine*, which also has some good languages to use it with (jython, groovy, etc)

  4. Quoth David:

    I'd probably have a similar cow if I had to deal with poorly designed code in any language I didn't know very well.

    Every language has it's place. As far I can tell, J2EE apps are the only thing Java's particularly good for (and even then, only if well designed).

  5. Quoth NameNotFoundException:

    Wow! It happened to me, too! I recently read a really shitty book in French, and I must say, it was absolutely loathesome. The characters were stupid, flat and outright ridiculous, the story was boring and not worth the paper it was printed on, there were spelling errors, cuss words and bad grammar anywhere, and the whole book really sucked big time. Besides it was 1000 pages long where 10 had fully sufficed.
    Really, French is such a crappy language. I can't understand how people can be so dumb and still write books in it. Abominable and disgusting! The worst thing about French is that it actually just barely can be used to express most things in it, which only continues to encourage people to use it.

  6. Quoth numerodix:

    I'm wondering if this is a good time to mention jruby. I hear it's nice when you inherit a java codebase and you can interface it from ruby without writing anymore java.

  7. Quoth Hates_:

    Yes, Java has it's flaws, but it sounds like your gripe is really with author of the code you had to maintain. You could produce the same sloppy and poorly documented code in just about most languages.

  8. Quoth ph0enix:

    isHasDeletePrivilege(). 'nuff said.

Leave a Reply

You can use these tags in comments (Note: HTML is automatically escaped inside <pre> tags, nowhere else, so if you post source code, put it in <pre>):

<pre lang="some_programming_language"> 
<em>
<strong>
<a href="url">

NOTE: Comments are automatically spam-filtered. If your comment fails to appear, it was likely munched by the filter. Try not to link-spam or post anything that looks like it was typed by a robot.