[01/12/2019] Java Woes

Recently I've been writing code in Java a lot. I find myself disliking Java quite a bit in some respects, so I'll list my problems with it here.

Firstly, it's Object Oriented. Now I'm not here to compare Programming Paradigms, Object Orientation has its place and times where it's very useful. In Java though, you often see a few patterns from this coming out. Firstly, singletons typically as controller objects, which could have been done as pure variables in the code(Or just their own data structure, like a struct in C). This isn't inherently bad, but I see it as a natural problem of Java. This is derived from the OO principles. There are 4 of these: Encapsulation, Inheritance, Polymorphism and Composition. Firstly, lets look at Encapsulation. Java forces all objects to be encapsulated, which is fair, and arguably good because it means the variables you'll be accessing with the Objects are near it address-wise. This means that when the data is gotten from RAM, local data is also put into Cache, as the idea is that if you need data, you'll also need data near it. The thing about this though, is it can be likened very closely just normal data structures, as the addresses for variables in these data structures are close together address-wise. As a result, the benefits of Encapsulation in Java, aren't terribly huge.

Enums in particular in Java are just terribly implemented. In langauges like C, Python and GML(Gamemaker Language), enums are just integer values which are given a "name". This makes it particularly useful for indexing certain information about Data Structures or Arrays if you have information about them. In Java though, Enums are overengineered and rely on HashMaps between the enum value and it's corresponding integer value. It's an overengineered solution to a problem that doens't exist in most languages.

Generics. In Java, Generics are just simply really ugly to write, and can get even uglier fast. In languages like C, you can get around this problem with similarly weird fixes. I think C++ implements them much better, but I'm not sure. Typeless/Weakly typed languages like Python and Javascript don't really have these issues(but you get issues from how they are weakly typed).

Java idiomatic programming. Idiomatically in Java, you write getters and setters to maintain the Encapsulation. Sometimes this is just idiomatic and silly, and not everything needs getters and setters(If every value has a getter and setter, you might as well make your variables public). Static variables and Static methods are often discouraged as well. It took me a very long time to find out why, but it's mainly because Static variables represent a "global" state, so it's much harder to reason about. It's also generally against the idea of the Object Oriented Paradigm. A fantastic Stack Overflow Question sees a lot of the reasons explored.

Java encouraging over engineered solutions. You'll get a lot of "Do-er" methods and classes. It's not necessarily bad, but leads to writing unnecessary amounts of code, which in turn increases the amount of code written, which in turn reduces the reliability of code. Overengineered solutions also tend to be overly complex as well.

Another reason is the Garbage collector, forcing you to work around it, as it kicks in whenever it feels like it, which can cause a performance dump when it's calculating the number of references that can't be accessed. This amount of memory manipulation causes performance drops, and results in low-level code being harder to write. I personally, haven't run into this issue, but I imagine if I used Java much more I might encounter it.

This blog post is by no means exhaustive reasoning on why Java is a bad language. It's useful and also instructional to understand it. I actually like it quite a bit, as well the Object Oriented Paradigm, but not every problem fits it. The JVM is also a very cool concept.

<Latest><Next><List><Previous><Oldest>
Take me home!
Bad for health, Good for education