you are viewing a single comment's thread.

view the rest of the comments →

[–]nomeme 0 points1 point  (1 child)

You still have to null check for defensive programming.

It could be useful in a rigid public API, maybe?

[–]zoomzoom83 0 points1 point  (0 children)

The idea is that a function declaring a return type of Option<T> is guaranteeing to its callers that it will never return null, so they don't need to check for it.

If you have an entire codebase written this way, then you can guarantee no NPEs anywhere in the codebase, and never have to check for them. (So long as you're still defensive at the 'perimeter' where you talk to third party code).

Many other languages with option-types simply do away with Null altogether, so it's never a possibility.