Why I Love Java

...it’s not just because I love being a contrarian.

For background see jwz’s delightful rant about Java. When I say I love “Java”, I mean only the langauge and perhaps sort of the security model. The standard library and the virtual machine are not what I mean. (It’s real hard to love parts of the library.)

Basically, you can use Java to write C, but with safe and sane semantics. Integer overflow has defined behavior, out-of-bounds array accesses have defined behavior, both the compiler and the run-time know the types of objects and have defined behavior on bad casts... generally, you can write code in Java and have the nice, warm feeling of at least basic safety. This frees you up to worry about application-domain vulnerabilities, which is still painful, but at least you aren’t ice-skating through a laser-maze like you are in C and C++. I’ve been working a lot on hardening PDFium lately, and I honestly long for the sanity that this tiny amount of safety brings.

Java’s simplified integer type system also makes programming profoundly easier — very few C/C++ programmers understand the billions of integer types and typedefs, and confusion can be disastrous.

Similarly, strong static typing is essentially the only reliable way to develop large software projects with large teams. And while it’s best not to have to do that, (a) sometimes problems are just plain large; and (b) even small projects and teams can benefit hugely from strong, static typing. Types are documentation, types are safety, types are lightweight formal methods. Types are practical!

Of course, the other baggage that comes with Java — the VM, the standard libraries, the fully-dynamic GC, the broken String type and the ugly attempts to repair it — is sad.

What we need is a language with the relatively straightforward memory- and type-safety of Java, without the poor abstractions and poor performance. Go is close, but for the GC and lack of generics; Rust is close, but for the ridiculous Ruby-like syntax and complex semantics; C++11 is not close at all and is evil and bad but I kinda like those new smart pointers.