I agree that it's good to look at commonly bad things again and critically evaluate if, why and how they are bad. And since I disagree with you on a few fronts, I figured, I should argue my thoughts.
(Note that I've not watched the video, but only read the article so I apologize if you've addressed some of it in the video.)
I agree here. I do even think that non-checked Exceptions are a problem.
Exceptions are a form of a return value and since you don't have to specify them in the method definition, every Java method essentially has infinite possibilities for return values by default. However it gets hate because of how clumsily it was implemented in Java and so noone wants to write the throws line by hand. I'm not sure how to best solve it, though.
I don't think the common problem is that null exists, but rather that Java doesn't support you with it at all.
Functional languages like Haskell have nulls in the form of the Option monad. In Java every object may be null until proven otherwise.
When people complain about null-safety in Java, they complain about the lack of compile-time checks. The compiler could always find out whether a variable might be null at a certain point, but it doesn't tell the programmer. It would make sense to have it explicitely in the syntax, too.
Yes, there are annotations and external tools, but they will never be able to approach a built-in solution.
You could even add null safety later like C# did.
So let's go throught the points again:
...is actually worse because of the null unsafety. For one, when the compiler knows when a variable is never null it can skip out on the check and you have one less fork. Of course the Java compiler could still do it, but it has to be done additionally instead of having it as part of the language syntax.
More importantly, however, is that throwing an exception is slow. In high-performance Java code, you can almost never afford creating and throwing an exception.
When people mention getting a null pointer exception in production I usually ask: what would have been the alternative?
A compile-time error.
And if you don't want to use a dummy object, then throw an exception yourself that better describes why it happened. Maybe even something like UnexpectedNullInDatabase.
I guess this is subjective. Personally I prefer having options like ?. and similar, because I will have to do these checks anyways if I want to program defensively. But of course it's more syntax to learn.
The complex objects aren’t supported since they contain null retrieved from external sources.
Why not? Data from external sources may always be corrupt and you should check for it. So in the case of null the language should always assume that they can be null and the programmer should handle it however they see fit.
I think it got a lot better in Java 17. My main issue with the boilerplate code in Java were simple DTOs, but with records they become pretty small now, too.
As for semi-colons: I prefer the look of no semi-colons ^^ It's purely asthetic though and I see the value of them.
I guess I mostly disagree with you on the null front. I do think that "fail-fast" starts at compile time and errors with null are some of the easiest to bake into a language.
Jacek Fleszar
fleszarjacek
Helpful 👌