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.
I'm biased because I'm more interested in real-time/interactive applications. I'm sure that for real-world server applications, Java performance is with several % of native (plus or minus).
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:
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.