r/programming • • Jul 05 '15

Fast as C: How to write really terrible Java

https://vimeo.com/131394615
1.1k Upvotes

394 comments sorted by

View all comments

Show parent comments

8

u/[deleted] Jul 05 '15

If you mess up a method in C, you cause memory leaks, segfaults, or random corruptions that are hard to track down. In Java, it's not possible to make those kinds of mistakes.

I do agree with your overall conclusion, but don't agree with that last sentence.

You can certainly have memory "leaks" as in your program using unbounded amounts of data - typically because you have some cache that you aren't clearing, but sometimes for obscure reasons. I remember another team in a company I was working for spent weeks and weeks searching for their "leak-like" problem. It turned out that if you created an instance of java.lang.Thread and never start it, it cannot get garbage collected (not sure if this is still true as I haven't written much Java in the last several years).

While you can't get "random corruption" as in "walking over memory" you can certainly get unexpected side effects, often due to the fact that Java is almost always passing pointers around in method calls and returns, so it's possible that the instance Foo whose contents you are modifying might be also be contained in some completely different structure elsewhere as a derived type...!

I do agree with your conclusion:

It's just a faster language to write large projects in with a group of differently skilled developers, even if it's not as performant.

Java lets a company use codemonkeys who might not really understand the details and traps within the language itself. I write in C++, and it's nerve wracking when you have people touching the codebase who don't understand all that complex weird cruft that goes with being a C++ programmer in 2015.

I actually like C++ better than Java - C++11 is the bomb! But I have to be realistic - the barrier to entry for Java is significantly lower, and the IDEs significantly more effective in general, and specifically in helping to prevent foot shooting incidents.

1

u/rcode Jul 06 '15

so it's possible that the instance Foo whose contents you are modifying might be also be contained in some completely different structure elsewhere as a derived type

Isn't that basically a race condition?