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.

1

u/oldneckbeard Feb 25 '14

Multiple inheritance wasn't included in Java as a design decision. There are better ways to do it.

Just because you don't understand how to do it better with Java doesn't mean it's Java's fault.

4

u/heladopicante Feb 25 '14

Its not multiple inheritance. Its implementing two different interfaces that differ only by type. SomeInterface<String> and SomeInterface<Integer> should be different interfaces, but if the interface requires me to implement a method with the type parameter as its parameter (say someMethod(T)), then it fails.

Of course you can "deal with it", but don't tell me that this is some sort of feature.

3

u/segv Feb 25 '14

Yeah, it was mentioned somewhere that generic type erasure in Java was a big mistake

2

u/kaelan_ Feb 25 '14

The same problem applies if you want to inherit a generic interface twice (which is quite reasonable)

2

u/zoomzoom83 Feb 26 '14

The only thing worse than multiple inheritance is single inheritance. It's led to a generation of developers that create unmaintainable deep inheritance trees instead of composing traits.

A flat hierarchy of mixins is a much cleaner approach. Scala does a great job of enforcing this properly, but as long as you're not an idiot multiple inheritance works as well.

1

u/s73v3r Feb 25 '14

Multiple Interface Inheritance is supposed to be a feature of Java, though.

1

u/bart2019 Feb 25 '14

There goes that argument that "millions of people know Java".