DEV Community

Discussion on: Unhealthy Code: Null Checks Everywhere!

Collapse
 
olvnikon profile image
Vladimir

This way of handling nullable objects reminds me a special type in Functional programming called Option (or Maybe). It keeps two values: None and Some(val). While Some always keeps a real not null value and you can map it, None has nothing but it is not null.
I would also apply this pattern instead of creating null versions of objects because it is more generic and covers all nullable cases. For example, fp-ts provides such utilities as fromNullable.

Thread Thread
 
jamesmh profile image
James Hickey

Agree. This was a solution I debated whether to include in the book or not. Due to not wanting to take forever with the book, I decided to exclude it.

But I agree, there are many situations where using the option pattern works very well 👍