Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I can pinpoint several mistakes in that blog post:

* Java has had escape analysis for decades. What it doesn't have is value objects. But there are plans for that in the works.

* The rant against bytecode is... I mean, there's a reason why you've had projects like LLVM whose (original) goal was to bring something like JVM bytecode to native code. And it's not for portability reasons, it's for the ability to do things like install-time optimizations. Also note that, for example, iOS distribution also relies on the ability to deliver bytecode instead of native code for those kinds of late optimization opportunities.

* The C++ standard library absolutely uses exceptions for all sorts of silly errors. std::vector::at, for example, throws an exception on a range error. The reason why this isn't obvious is that the more common methods just go for undefined behavior on errors instead of using exceptions, which is hardly a design to be emulated.

* I'm confused as to why the author hates try/finally so much, given that it's morally equivalent to RAII and defer. And there's no mention of the try-with-resources, which brings an interface much like RAII to Java.



Thanks for feedback. I wonder what you would classify as a "mistake", though. I don't want to say anything that's incorrect, and definitely invite corrections.

> Java has had escape analysis for decades. What it doesn't have is value objects. But there are plans for that in the works.

I'm not sure what you mean this contradicts. Let's say it lands. Which of my points does it invalidate? (also, you know, Java has had ~30 years to land this)

Edit: ah, I see what you mean. Basically you're saying that because of escape analysis, Java can avoid stuffing literally all objects onto the heap for the GC to collect. Sure, that's one of the millions of heroics that Java has added to manage the mistake. The GC has also added more genius algorithms than maybe any other code in history. And yet, a very large percentage of all that work is just to work around a mistake in the language. And it'll never be fully mitigated.

> The rant against bytecode is[…]

Reasonable people can disagree on the values, but what's the mistake?

> iOS distribution also relies on the ability to deliver bytecode instead of native code for those kinds of late optimization opportunities.

So did (does?) android. I remember those "optimizing apps" loading screens on every update. This is actually exactly my point: None of this requires that the IR / bytecode is, itself, "executable".

> The C++ standard library absolutely uses exceptions for all sorts of silly errors

Nowhere near Java. It's a difference is philosophy, don't you agree? Comparing C++ and Java, you'd agree that Java doubled down on exceptions, right?

And that's what I'm saying the mistake is.

I'm not saying that std never throws errors. But that's also not the case in Rust or Go. But I'm sure you agree that panic in Rust or Go is worlds apart from exception use in Java?

C++ (standard library API, at least) is much much closer to Rust and Go, than to Java. Like, no contest.

> I'm confused as to why the author hates try/finally so much

Not "try" so much as "finally". Compared to RAII or Go's "defer", it's a very convoluted and (in my experience from various codebases) very error prone way to hopefully remember to undo everything (and if a resource acquisition is added, to remember to release it way down there in different code).

It's morally equivalent to defer, yes, but unlike RAII it's not automatic. Even compared to Go's defer and (not guaranteed to be called) finalizer, it's easier to get wrong.

Defer is better than finally, but RAII is better than both.

> try-with-resources, which brings an interface much like RAII to Java.

True. I have no criticism of that pattern, which is why I didn't criticize it. :-)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: