home blog reviews contact

2020-04-10

Why I Hate Java

There are only two kinds of languages: the ones people complain about and the ones nobody uses.
— Bjarne Stroustrup, The C++ Programming Language

Let me preface this by saying that this is just my biased opinion, and a lot of my disdain for Java is based me not liking the kinds of problems that Java is most suited for. I should also mention that I could write a similar post about many, many other languages (and probably will at some point).

Verbosity/Boilerplate

Java just rambles on and on and on. Stuff like writing public in front of every single public method. Having to specify the type multiple times for each variable (at least until var became a thing). Forcing everything to be a class (creating a lot of boilerplate). The naming conventions Java programmers encourage don't help either. I don't want a goddamn fuckingBullshitAbstractionFactory, thanks though. Better write new when making a new instance of a class, even though there's only one way to make a new instance in Java.

Generics

Java handled generics in just about the worst way imaginable. Instead of generating code with the generic type filled in, and using that, Java relies on casts to implement generics. This has a runtime cost, first of all, but also hobbles generics. I can't create an object of a generic type inside a generic method, for instance, or check whether something is of a generic type at runtime.

Missing Features

Say what you will about C++, at least it lets me do what I want. Programming in Java after using C++ for a while feels like I've had an arm chopped off. No more method overloading, you might abuse it. No unsigned types, that's too complicated for you. No standalone functions, better write a class to put it in.

I also include things like not having very much control over memory layout here. Most other "similar" languages (C# is the most obvious example) include some way of specifying whether something should be heap- or stack-allocated. Hmmmm, now Java people are missing this feature and are working on a way to shove this back into Java. I'm sure that'll turn out great. It seems like Java people are slowly adding back all the things Java originally left out in the name of "simplicity".

UTF-16

Ah, the worst of both worlds. Some stuff doesn't fit in a single character, but also, you can't index in constant time. Wonderful. (This isn't really a concern in practice, just really, really bugs me for some reason.)

"But Java is Cross-Platform"

Oh, as opposed to pretty much every other modern language which isn't?

Conclusion

I generally don't like programming in Java because it's just not suited for the kinds of problems I like. I did an FTP client in Java once, and a server in C. The Java client involved me having to put 2 or 3 layers of abstraction on top of what was basically a character array in order to do anything with it. The C server, you guessed it, used a character array. How easy was that.