Re:Overhead of Returning Optional Values in Java and Rust
by Zababa on Saturday October 16, 2021 @01:57PM
(#28889883)
> Using null is fine. You probably don‘t need Optional. Using Optional is often „clever“ (=bad) overengineering.
Option types are 8 years older than null (ML: 1973, null: 1965). There's nothing clever about it. It's simple to understand, and is an explicit wrapper around an object, while a pointer is an "implicit" pointer around an object. Option<Obj> is clear, you know that it can be something or nothing. Plain Obj is deceiving.
> Every NullPointerExceptipn my code ever caused was good, because it helped find an error state that had no acceptable default non error state alternative.
That's the point of option types and pattern matching, it can force you to handle both cases.
Option types are 8 years older than null (ML: 1973, null: 1965). There's nothing clever about it. It's simple to understand, and is an explicit wrapper around an object, while a pointer is an "implicit" pointer around an object. Option<Obj> is clear, you know that it can be something or nothing. Plain Obj is deceiving.
> Every NullPointerExceptipn my code ever caused was good, because it helped find an error state that had no acceptable default non error state alternative.
That's the point of option types and pattern matching, it can force you to handle both cases.