Why can values be null in .NET? Is this superior to having a guarantee where everything would have a value and nothing call be null?
Anyone knows what each of these methodologies are called?
Either way, I am not very knowledgeable on this, but wouldn't having a value for everything makes things easier, in terms of simplicity, i.e. eliminating null checks, and being able to write more streamlined algorithms that doesn't have to branch out for checks.
What are the pros and cons of each style in terms of performance, simplicity, parallellism, future-proofing, etc.
As appealing as a world without
null
is, it does present a lot of difficulty for many existing patterns and constructs. For example consider the following constructs which would need major changes ifnull
did not existnew object[42]
. In the existing CLR world the arrays would be filled withnull
which is illegal. Array semantics would need to change quite a bit heredefault(T)
useful only whenT
is a value type. Using it on reference types or unconstrained generics wouldn't be allowednull
. That wouldn't be possible in a non-null world hence fields whos type are reference types in struct's would need to be disallowedNone of the above problems are unsolvable but they do result in changes that really challenge how developers tend to think about coding. Personally I wish C# and .Net was designed with the elimination of null but unfortunately it wasn't and I imagine problems like the above had a bit to do with it.