News for hackers. Stuff that matters.
Re:Overhead of Returning Optional Values in Java and Rust by shawnz on Saturday October 16, 2021 @05:03PM (#28891485)
Why not just chain the happy case by ignoring nulls, and let any potential NullPointerException bubble up to the point in the code where you would have had an "Optional.orElse" or whatever? Isn't that often just as easy? If you want it to be explicit then you could just add "@throws NullPointerException" to your javadoc. And of course having Optional in your type signature doesn't guarantee you'll never return empty objects (or even null).
Re:Overhead of Returning Optional Values in Java and Rust by valenterry on Saturday October 16, 2021 @09:36PM (#28893217)
Because then you cannot differentiate anymore between "NullPointerException as a bug" or "NullPointerException as a feature".

E.g. you might want to return the streetnumber of a user's address. When a NPE is thrown, was it because there is a bug somewhere in the code or because the user's address has no street number?

With Optional, it is clear: there was no street number.