Tag Archives: java

Growing a Language

I was recently pointed at a talk given by Guy Steele (who, amongst other things, co-invented Scheme), given at the 1998 OOPSLA Conference, entitled Growing a Language.

In it, he talks about the need for Java to add features that will allow the language to grow as users add to it, specifically suggesting two features (one of which has been added, albeit poorly, and one of which is still yet to be implemented); but the real value of the talk is not what he says, but in how it is presented: whilst giving that away would be entirely unfair, I recommend watching at least the first 10 minutes of it, to allow you to figure out what’s going on.

So, if you get a spare hour in the near future, I suggest you watch it.

Why I hate Java (part 1)

People have often asked for my opinion on Java (the programming language, not the Runtime engine, or the Coffee), and my response is normally a very unreserved expression of hatred. I have condensed all of my evidence from the past year, and the result is the following piece of code:

 public class Dodgy{ public static void main (String[] args) { boolean a = true; boolean b; if (a == false) { b = true; } if (a == true) { b = false; } System.out.println(b); } } 

Whilst this code looks harmless, let’s see what Java does when I try to compile it:

chris@blackboard:~/src$ javac Dodgy.java Dodgy.java:14: error: The local variable b may not have been initialized System.out.println(b); ^ 1 problem (1 error) 

It is obvious, from such a trivial example, that b will be initialised when line 14 is reached, however, Java prevents my code from even compiling. This demonstrates one differentiation between Java and C (or C++): Java does not trust your judgement. With appropriate syntax changes, that code would have been valid C code, but in Java it is illegal.

Whilst I would approve of such a case being a compiler Warning (I could then flag a -Wall or similar, and have my compiler abort when it finds such an issue), but causing such a thing to be an error is irrational.

Of course, all cases of whether a variable is initialised or not cannot be verified: a general purpose algorithm to do such a thing can be proven to not exist via reduction to the halting problem; so why should Java even attempt to do it in the first place?

So there you have it: Java has a distinct lack of trust in the programmer who uses it, and this is why I dislike it.