Functional Principles - Avoiding nulls
Nulls make C# code dishonest as the method signature doesn't specify that a null may be returned or if an exception is thrown if something goes wrong.
The below code compromises the Fail Fast Principle as it doesn't fail until you try and access the reference type which is set to null. Ideally we want to know on the first line that something is null.
The Maybe struct helps to define whether something is nullable or not.
Enforce the use of Maybe of nulls by using Fody.NullGuard.
Install NuGet package NullGuard.Fody
Comments
Post a Comment