I once read that having nullable types is an absolute evil. I believe it was in an article written by the very person who created them(in Ada?) I believe this is the article
We'd create all kinds of strange constructs to convey the message of an object 'being invalid' or 'not being there', as seen in the other answers. A message that null
can convey very well.
null
or using the Null Object pattern.Personally, I would write some C# preprocessor that allows me to use null
. This would then map to some dynamic
object, which throws a NullReferenceException
whenever a method is invoked on it.
Back in 1965, null references may have looked like a mistake. But nowadays, with all kinds of code analysis tools that warn us about null references, we don't have to worry that much. From a programming perspective null
is a very valuable keyword.