Wednesday, May 2, 2012

Why Java?

Is Java really relevant? After perusing the class library from Java and comparing the language to C++, I came to ask myself: Why Java? On the bad side, it runs slower than C++. It does however tout a more thorough framework than STL, but then again, there are plenty of frameworks for C++ which include smart pointers and garbage collectors as well as every imaginable class and function. In fact, every argument in favor of Java, I can make the same or better argument for C++. The only one in which Java shines is with mobile phones, and devices with small footprints, which use many different tiny applications. In this case, portablitity and size win out.

Where both languages seem to fail is with functional programming and "terseness." They both don't handle implicit types very well, as do the "Caml-like" languages. Both make for a lot of unnecessary keyboard strokes. Java however is much less terse even than C++. In fact, it is the least terse language out there.

The truth is that C++ could be used in almost every place Java is used. Performance and portability is usually much better with C++.

What I don't understand, is why was Java invented at all? At the time, compiling to bytecode probably seemed like a good idea. You could squeeze a few more bytes out of your project. It was argued that it could run everywhere, just make the VM...

The C languages, in general, now-a-days are considered quite verbose. O-Caml would be a wonderful replacement for C++, if however, the garbage collecter was optional. C# makes use of a ValueType, which until recently was not possible in Java. This allows for direct passing of objects, bypassing the heap.

In summation, why I avoid Java is threefold:
1. I haven't found a situation where Java did better what I could do in C++.
2. Java is too verbose.
3. Java interfaces terribly with the operating system.

In general, I prefer to develop applications in C++ on top of a portable framework, like Milan. And then any OS specific calls, I can wrap with #ifdefs. This way I am guarenteed that my application will perform exactly as suspected, without any performaces surprises, which prove impossible to tweak.

If everyone developed with Milan and C++, we would never have the case of the buggy and slow application, which runs well on one machine and horribly on another.

No comments: