Tuesday 30 March 2004

Why Do Java Developers Like to Make Things So Hard?

In Why Do Java Developers Like to Make Things So Hard? James Turner makes a comparison between Java and Perl:

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.

You should also check out the mini-language war in the comments

Here's an excerpt from another rant about Java:

Here's "Hello World" in Perl.

print "Hello, world\n";

One line, one function, one string. What does it do? It prints "Hello, World". Explaining it is almost as simple as writing it. The trickiest part is possibly the newline.

And here in Java:

    public class HelloWorld { 
        public static void main (String[] args) { 
            System.out.println("Hello, world!"); 
        } 
    }

This most basic of all programs drags in the concepts of class, privacy, types, methods, the magic "main" method, the String class, arrays, class methods vs object methods and chained method calls.

Ouch!

Programming Languages ought to be tools that get the job done without any distractions and while elegance has its place in code, it shouldn't get in the way.

My choice of programming language is thankfully no frills but Java isn't and its level of abstractions gives it a steep learning curve and this is why we've mostly been advised to learn Python or Perl or PHP as our first programming language before tackling Java.

However, I hear Java can be a beautiful language and I hope to make its acquaintance sometime in the future.

Related Reading