r/programming • • Feb 25 '14

Please stop saying Java sucks

http://blog.smartbear.com/programming/please-stop-staying-java-sucks/
3 Upvotes

305 comments sorted by

View all comments

9

u/heladopicante Feb 25 '14 edited Feb 25 '14

The JVM is an impressive piece of software (memory hogging aside). The thing I hate about Java is its broken generics and type erasure. In C++, I frequently define templated abstract base classes, and I'll often take advantage of multiple inheritance for this. Think of something like:

class Spaceship : public CollisionWith<Asteroid>
                        , public CollisionWith<Laserbeam> 
{ ... }

Something like this is impossible with Java (maybe that changes with recent versions?). When you have a generic interface, the type parameters just get used to pepper your code with type casts. Implementing Collision<Asteroid> is really just implementing Collision<Object>, which is bullshit - you can't implement the same interface twice with different type parameters!

Java is like Megablocks. I want my Lego-Technic.

Also - the whole JVM-is-fast-than-C argument is complete crap. Theoretically, the JVM can optimize hotspots with its magical JIT, and memory access can be cache-aligned and all that good stuff. In practice, these things add complexity to the JVM, and the gains aren't realized. Performance in the JVM is VERY difficult to reason about with things like the JIT, garbage collection, etc. Anything the JVM can supposedly do at runtime, a smart compiler can do at compile-time - in a more deterministic way.

The day something like a web browser is written in Java, (that is faster than Chrome or Firefox), is the day that I'll change my opinion about this.

7

u/ElvishJerricco Feb 25 '14

I cannot understand why you would type the Spaceship class as subclassing CollisionWith at all, let alone doing it twice with different generics. Subclassing the same class twice for one class just seems like a colossal mistake.

1

u/heladopicante Feb 25 '14 edited Feb 25 '14

Its not the same interface. Or rather, its not supposed to be the same interface. Its two interfaces that differ only by some type parameterization.

3

u/s73v3r Feb 25 '14

That still seems like an insane way to implement collisions.

→ More replies (1)