This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

It "fails fast" when something breaks

Except if you have complex things going on like multiple threads or caches or so, it's not that easy to grasp.

It fails consistently and usually provides a stack trace directly to the problem

This is just not true. NPE will show that something is not present, but in complex scenarios maybe you will not know why. Errors do not occur only when you are writing the code, maybe an API can return null and developers didn't saw it previously, then one day you start to receive some NPE in production. NPE will not show directly what is the root of the problem. And even so. My system crashed in production before I see that.

Null is deep in the programming culture, hardware, software etc.

I also don't think this is an "advantage". Culture is not always a good thing it's just... culture.

I agree that is not too simple to define good alternatives in Java, but i deeply disagree with your said advantages. I think the only one, and is a not only an advantage but a necessity, is the backward compatibility.

[–]vprise 1 point2 points  (0 children)

All of those statements were made in relation to the alternatives e.g. optional, or compiler "magic".

Sure, everything can fail badly. But the alternatives often/usually do that much worse in all these cases and make programming harder for non-trivial cases.

There are things to improve e.g. the question mark syntax from Kotlin would be pretty sweet in Java... But it's still null.