Sunday, March 24, 2013

Java can get annoying

There are times when Java is wonderful, such as its cross platform-ness and its garbage collection. Then there are times when I feel that there could be some ways to improve Java.

Before I go about talking about all of Java's shortcommings, I just want to say that Java is pretty well done. Compared to languages that came before it, Java is a lifesaver. It's also the reason we have C# (for all the people in Microsoftland) and the reason we have all of those strange languages that decided to run in the JVM (for all of the people who put up with Scala and JRuby). Overall, it is the language that people like to ask about, since it is the one that people know about. The syntax is clear, and it doesn't have 3 trillion ways to print out a single line of text. Even so, there are times I wish Java was better.

  • Consistency. String and array use length when you want to determine their length. On the other hand, the List interface uses Size. Please choose one or the other, I don't like to have the compiler spew errors about such pointless subtleties.
  • JRE. If you make a application with Java (and you are mainly developing for windows), its a pain to make sure that the user can run your application. Hopefully, they will have the same version JRE as you did when you compiled it. If not, the application might not start. So you decide to bundle the JRE with your application, but that seems like a strange extra step for a language that you "write once, use anywhere"
  • Parsing JSON. Regardless of the parser that you choose to use, you will either get a zillion warnings or cast everything until the apocalypse. The compiler has no faith in the programmer that they got the type right, and is determined to save humanity by refusing to compile until every last 'error' is addressed. What a nightmare.
  • Generics. I understand Java's reasoning with generics, but I still wish it was done better (like in Scala) Due to the way java separates primitives and objects, some classes contain one method for all objects as a parameter, and then a zillion different methods for int, float, double, long etc. Wrapper classes are also necessary if you want to place an int into a List. While they have made substantial improvements regarding how they wrap and unwrap the primitive, it's still rather inconsistent to type List rather than just List. Sure, it tells the coder that the List is actually storing Integer wrapper objects rather than ints, but I don't think that will cause anyone to reconsider how they write their code. It would be a nice note to make in the docs, but not something that anyone really cares for.
  • Security. You've read the articles. I don't need to say anymore.
I've always been curious as to why Sun never bothered to give the option of compiling to JVM or native. In the early days, Java was turtleneck slow and it would have been a much more compelling alternative to C++ if the performance gap was smaller. That isn't such a big deal now, with better computers and a more mature JVM, but it is still something that I will never understand.

No comments:

Post a Comment