Longing for a Simple Java
Did you ever wonder why in virtually any language you can run a small snippet of code in 10 seconds but it takes projects, source and binary directories, packages, and lots of text before I can do this in Java?
This is an interesting question because Java is loosing some steam in the area that is considered its adopted home: web applications. One big argument people mention when they switch to PHP or Ruby is that the development iteration of write, debug, correct is so much easier to do in PHP. And you know, I think they are right. What is wrong with today?s Java that causes this problem?
One key problem SUN has handled miserably is shell integration. It is surprisingly hard to make a simple program that can be used from the command line. Many useful command line programs are developed in c, tcl, perl, python, php, bash, etc. These programs are indistinguishable from native programs. A hello world in C requires:
#include <stdio.h>
int main() { printf("Hello world"); }
# cc hello.c
# ./hello
If I put the resulting executable in /usr/bin (on linux based systems) or in the Windows system directory, I can use this command anywhere. Not only works this for C, it also goes well for perl or any other installed language. In contrast, Java does not support this type of development. You have to setup the classpath, compile the code, and then you end up with a class file that is not recognized by the system. So you are faced with two choices: you type java ?cp . Hello or you write a script file.
This may not sound like a big deal, but in reality it is this kind of simple roadblocks that make the life of a developer harder. Developing is learning, and we often need small snippets of code or small utilities to achieve the greater goal. Additionally, it makes deployment really hard. Take a look at the ant distribution, it is surprising how many scripts they have to provide to support the "write once, run everywhere" mantra. And those are not simple scripts either.
However, this is not the only problem that Java developers face. There is just too much cruft in writing ordinary Java web applications. Obviously the language itself is crufty. Many of the constructs in Java are just plain cumbersome. Some constructs have improved, like for loops in Java 5, but the syntax from hell of inner classes has remained. Take a look at Python, or even better Smalltalk, and see with how much less cruft you can get away with. But if you think Java is crufty, take a look at Java Server Pages. Combine Java syntax with HTML and you have something truly unreadable.
However, the true systems from hell come when you combine Web Applications with Javascript, HTML, and XML descriptors. At least part of the Java cruft provides type safety so at least it pays for itself in some way. The bindings required between these different resources are hard to check but create very hard to maintain and debug systems.
The big question therefore: If we all desire simplicity, how do we end up with those complex architectures? How come that we always add features for rare (and sometimes bad) use cases to complicate the system for the majority? Why can we not leave simple alone?
Peter Kriens
posted by Peter @ Friday, January 06, 2006



