r/programming • • Feb 22 '15

Java Makes Programmers Want To Do Absolutely Anything Else With Their Time

http://www.forbes.com/sites/quora/2015/02/21/java-makes-programmers-want-to-do-absolutely-anything-else-with-their-time/
35 Upvotes

636 comments sorted by

View all comments

140

u/karlhungus Feb 22 '15

I have no love for java.

While it performs pretty well nowadays, it still isn’t competitive with C or C++ and, with a little love, Haskell and OCaml can or will eclipse it in that domain.

I didn't think this was true, i thought it was somewhat close to C (excluding startup).

For real-world production servers, it tends to require a fair amount of JVM tuning.

This is really seems like reaching for something to be a problem that isn't.

because it objectively sucks.

If people can't even define OO, it can't objectively suck. If you were making a pun i forgive you.

culture is one of mediocrity and bad taste, with MetaModelVibratorVisitorFactory

These kinds of strawmen make me feel like "I don't have to read another word this person writes."

0

u/[deleted] Feb 22 '15

[deleted]

5

u/bcash Feb 22 '15

except for a few unlikely scenarios where the JIT works perfectly

This isn't even a strawman. JIT will never "work perfectly", and it doesn't have to. This is very much a case of 50% of the effort delivering 90% of the benefit; most cases are "good enough" rather than all-but one being bad.

It's also wrong to call what Java does JIT. Compilation occurs during run-time, the same piece of code can and will be recompiled multiple times as it's running.

All this means that Java's performance is non-deterministic, which is a showstopper for a lot of applications, but not all. Being non-deterministic doesn't mean "bad", the average, and even 90th percentile I'd say, case is still very good.

Good enough that the difference between C and Java is within an order of magnitude in "real-world" cases.

Java's memory usage, however, will be much higher.

4

u/seventeenletters Feb 22 '15

But JIT can't fix your data structures (at least Java's can't), and heap fragmentation does terrible things to performance on modern CPUs.

4

u/bcash Feb 22 '15

No, but it's a similar principal. You can't force data structures to have a specific layout in a memory in Java in much the same way you can't force it to have deterministic performance.

But at the same time the work the JVM does do makes it less-bad than if you naively heap-allocating everything in C++ or other such languages. One of the tiers of compilation the JVM does, once the code has been run a few times, is inlining function calls followed by escape analysis; this means that most short-lived objects will be stack-allocated anyway. Also, by virtue of the garbage collector, there's little fragmentation in the heap; things allocated at the same time will almost certainly be near each other, the heap is compacted (although how, when, etc. depends on which version of Java and which GC; they can take significantly different approaches).

Of course, as an application developer, you cannot control any of these things; and as it runs on the bytecode after-inlining it can be surprising when it does (e.g. just because an object is returned from a method to a method in a different class, it doesn't have to be heap-allocated). But it does mean the average performance is no-where near as bad as the worst-case described whenever this issue comes up.

→ More replies (1)