Most programming languages including C# and Java use
null to represent the absence of value. Null references are convenient when there is no particular value to return as we can simply return
null without thinking too much about the consequences.
However, null references are notorious for causing bugs that can be found only at runtime with
NullPointerException. Tony Hoare calls it The Billion Dollar Mistake. He admits that null was introduced simply because it was so easy to implement.
One problem I found particularly irritating about null references is that some types have natural encoding of the absence of value. For example, we often represent the absence of a string with an empty string “”. It means we now have two ways to represent the absence of a string: either an empty string or null.
This is the reason why .NET String class provides IsNullOrEmpty. People use both
String.Empty so we have to check both to be conservative. Checking only one of them often leads a bug.
Having two values that represent the same concept often leads to bugs. Another example is
null and others prefer
null must be checked.
So I think it is crucial to have a single universal way to represent the absence of value. I think
Maybe type used in functional programming languages is a good start though hybrid languages such as F# and Scala still have
null to interoperate with .NET and JVM respectively.