Does C# 8 reference type nullability make Option/Result monad obsolete?

  softwareengineering

As the most common exceptions in my project are NullReferenceExceptions I’m trying to find a way to limit the occurrence of problems with unexpected or unhandled nulls to the minimum.

One of the possible solutions is to user Option monad or Result. As I understand, those guarantee two things:

  1. There will always be an instance of object to work with (because null now becomes an object)
  2. Programmer will be required to consider fail scenarios, because he can’t get to the underlying value without acknowledging the possibility of the two states that the value could be in.

Now, assuming I’ve added:

<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>

parameters to C# 8’s csproj file in my project, is there any reason I would still use Result monad?

  1. You can’t assign null to non-nullable variable now.
  2. As you get Nullable object now, it means that you need to check if it .HasValue first

New contributor

Piotrek is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT