DEV Community

Discussion on: NULL, "The Billion Dollar Mistake", Maybe Just Nothing

Collapse
 
simonhaisz profile image
simonhaisz

Interesting article on the various ways to deal with this classic problem.

I've worked with a few people who were big proponents of the functional decorator pattern but I've always found it awkward to read/use. I just find the Nullable/Optional wrapper approach more natural.

Another method that works with Typescript is to add compile time checks by enforcing the explicit null rule. That way for something to be null there needs to be an explicit "| null" added to the type definition if the value could be null. It's a softer enforcement from all these other methods but at least it gets the developer thinking about null.

Collapse
 
joelnet profile image
JavaScript Joel • Edited

The decorator pattern is not as clean as it could be. I still use it but sparingly. Type checking is also a great option when available.