Welcome!

Linux Authors: Michael Sheehan, Lavenya Dilip, Ian Thain, Bruce Armstrong, Ellen Rubin

Related Topics: Linux

Linux: Article

TURNER'S VIEWPOINT: Why Do Java Developers Like to Make Things So Hard?

TURNER'S VIEWPOINT: Why Do Java Developers Like to Make Things So Hard?

Usually, as Senior Editor of LinuxWorld Magazine, I restrict my potshots to complaining about how much work is left to make Linux a usuable desktop OS, or heckling SCO and Microsoft. But it's a little-known fact that I have an secret identity as a Java developer. So, for a change, I thought I'd take a potshot at Java.

First off, a caveat. I'm not some wet-behind-the-ears newbie who longs for Visual Basic. I've been coding in Java for over 5 years and have written 2 books on JSP development (MySQL & JSP Web Applications and Struts Kick Start, both from SAMS, run out and buy them right now). I'm a committer on the Jakarta Struts project. So I think I can claim I know my way around a polymorphism or two.

So when I say that Java developers seem to be in love with unneeded and confusing layers of complexity, I'm not say it from a position of ignorance. I'm saying it because I find myself frequently finding the Java way of doing something about 10 times as difficult as in other languages.

For example, I recently needed to automate encrypting and transmitting some files via FTP. Since I was already generating the plaintext file in Java, I figured it would be easy enough to tack on PGP and then send it. In fact, I already knew how to send it because I had other Java programs that did FTP. So all I needed to do was find a native Java PGP implementation, and sure enough, the Bouncy Castle folks had a native Java implementation free for the downloading.

Immediately, I ran into the thing I hate most about Java developers. They (as a group) are in love with how clever they can be. The Bouncy Castle code was a morass of Factories, multiple different classes that needed to be configured in order to make everything work right, and even at that I couldn't get it to work after a day of messing around. The mantra in Java seems to be to never hardwire anything, so that in the hypothetical "someday", you can rip out class X and put in class Y by just adding a Factory. The end result however, is code that's confusing to use, hard to maintain, and never seems to be very well documented.

In desperation, I turned to option 2, doing it in Perl. What a difference! One CPAN install got me the entire suite of packages I needed to make the Crypto::OpenPGP package work (and BOY could the Java community take a lesson from the success and good design of CPAN) The package was straightforward to use, maybe not the most elegant, infinitely extensable design possible, but easy to get up and working in 10 minutes.

I moderated a panel at COMDEX last fall where Rasmus Lerdorf (Mr. PHP) and a Perl proponent ganged up on the person representing Java, complaining about how slow it was and hard to develop in. I tried my best to help defend Java, but it was hard. The trouble is, I see their point.

Java is a great language. But for some reason, the Java community has decided to take it and make all the ancillary packages as complex and difficult to use as possible. It's like a racehorse that's had a wet bar and a hot tub mounted on it. The Perl folks have the right idea. Make supporting technologies that are simple to use, rather than so elegant that they become incomprehensible.

Imagine if the Perl cafe and Javahut were across the street from each other. You walk into Javahut, and ask to sit down. "I'm sorry," says the person at the door. I'm not actually the hostess, I'm a Factory class that can give you a hostess if you tell me what type of seat you want." You say you want a non-smoking seat, and the person calls over a NonSmokingSeatHostess. The hostess takes you to your seat, and asks if you'll want breakfast, lunch, or dinner. You say lunch, and she beckons a LunchWaitress. The LunchWaitress takes your order, brings over your food, but there's no plates to put it on because you forgot to get a CutleryFactory and invoke getPlates, so the Waitress throws a null pointer exception and you get thrown out of the place.

Dusting yourself off, you walk across the street to the Perl cafe. The person at the door asks what kind of seat you want, what you want to eat, and how you want to pay. They sit you at your seat, bring over your food, collect the money, and leave you to eat in peace. Sure, it's not the most elegant dining experience you ever had, but you got your food with a minimum of pain.

The long and the short of it is that, in my opinion, Java is a great language being destroyed by Rampaging Computer Science. There's a time for elegance, and a time for usability. If developers want to make the internals of packages flexible and extensible, that's all well and good. But the external interfaces should be clean, simple to use, and have wrappers for the most commonly accessed functionality. For example, in a PGP package, I should be able to encrypt or decrypt a file in 5 lines of code or less. After all, I can do it in Perl in 3.

More Stories By James Turner

James Turner is president of Black Bear Software. James was formerly senior editor of Linux.SYS-CON.com and has also written for Wired, Christian Science Monitor, and other publications. He is currently working on his third book on open source development.

Comments (55) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
James Turner 03/29/04 02:10:22 PM EST

Troll? Ok Loke, you come over to my house and make PGP work inside Java. Saying that Java isn't a scripting language is just an excuse to ignore things that Java is bad at. If I have a piece of Java code that is producing a fairly complicated report (that requires the full power of Java), and then have to wrap it all in a Perl script because Java can't handle actually delivering it to the end consumer, I'd say it's Java that's showing a lack of flexibility.

I *could* have written the whole thing in Perl, but chose to use the OO functionality of Java to make my report generation cleaner. The fact that I *couldn't* do everything in Java, because the "Java Way" was so complex as to be unusable, speaks more to the problems of Java developers than me not knowing what tools to use for what.

James

Phillup 03/29/04 12:50:19 PM EST

Over twenty years I've programmed with at least as many languages.

So, I won't claim to know any language intimately.

But... I have programed in Perl for the last five years. Why is simple.

Because Perl let's me leverage the last 20 years of programming. If they see a good idea in another language... they put it in Perl.

You will see a lot of people complain because of how Perl code looks. The simple fact is that you can write clean looking code... or ugly code. Perl doesn't care. It is your code... do it the way you want.

Perl's strength is that it let's a programmer program the way they want to. That is also it's weakness.

My advice would be to spend a few more years with a few other languages. You won't appreciate Perl until you know how elegantly it lets you solve some problems that you have used other tools for.

If you are looking for "structure" and don't have the discipline to enforce it yourself... then stay away from Perl.

xzzy 03/29/04 12:48:28 PM EST

Wvery time I sit down and promise myself to write a new script all tidy and clean in python, about five minutes into it I'm muttering "if this were perl I coulda been DONE by now" and quickly revert back to old faithful.

Billy_Gates 03/29/04 12:47:43 PM EST

I prefer python over perl. The resulting code is soo much cleaner.

I suppose it has to do with the old debate of losely or strict typed langauges. Perl is highly modular but I would hate to work in a team of 10 or more perl developers all writing in their own styles and methods. Shudder

Loke 03/29/04 11:50:09 AM EST

The article smells a lot of troll - he starts out with an apples and oranges comparison, and then spends the entire article arguing the wrong thing.

No one ever said that Java was simpler than Perl. Quite the opposite. The one thing that Perl has going for it is the fact that it's very simple to do simple things. I think everybody who knows both Java and Perl are very well aware of this.

Here's some news for James Turner: Java is not a scripting language. In the real world (sorry, Struts doesn't impress me one bit) we want flexibility. In order to have flexibility you need to have flexible libraries. Encryption is very important, and since Java is not a sinple scripting language one needs a lot more flexibility. More flexibility means more stuff to set up.

9 out of 10 Java libraries are very easy to use, but also very confugrable. Usually there is a DefaultXyz class that can be used to get off the ground in a single line of code. I'm sure he could use the FTP client library that was mentioned in the article with just a single line of code.

I wonder exactly why he could only come up with a single example of a hard-to-use library? Maybe because all the others were very easy?