News for hackers. Stuff that matters.
Re:New Features in Java 14 by james_s_tayler on Wednesday March 04, 2020 @03:21AM (#22482038)
In Java the Option of T type blows up the same way a NullPointerException does if you try to use the Option's value when it contains none.

I agree. In Java at least the semantics are practically identical.

I can't comment on Rust. I suspect it does a slightly better job.

Crystal is another language where there is no null. It's quite cool.

Re:New Features in Java 14 by steveklabnik on Wednesday March 04, 2020 @08:22AM (#22483500)
Rust refuses to compile, because an Option<T> type is a different type than T, so if you try to use it like one, you get a type error.
Re:New Features in Java 14 by swsieber on Wednesday March 04, 2020 @10:37AM (#22484619)
Java would also refuse to compile using an Optional<T> where T is expected.

Java and Rust are practically the same regarding the differences between Optional<T> and T (java), and Option<T> and T (rust). Optional<String> in Java has the `.get()` method which corresponds to the `.unwrap()` method in Rust. And in both are different different types than String in their respective languages.

But in Java you can have an Optional<String> that's null, not just empty. So that's three states - null, wrapping null, or wrapping a value.

I'd say the big difference is that in Rust you can have places that refuse nulls (e.g. using T instead of Option<T>), so you have well defined points of control/checking. That, combined with the difficulty in recovering from a panic (the equivalent of a null pointer exception when trying to unwrap a value that's missing) and the Result type, are Rusts real strength wrt. missing values.

Re:New Features in Java 14 by steveklabnik on Wednesday March 04, 2020 @11:42AM (#22485280)
I think we are saying the same thing, from slightly different perspectives. That Option can be nullable means that it can be used where it is not actually that type, without a type error, is what I’m saying.