I am happy to note that this suggestion has been at the very top ever since I wrote it more than five years ago. To understand its popularity, one can simply enter "billion dollar mistake" into any search engine.
Non-nullability is difficult to retrofit into a language like C#. There are many approaches, who solve the problem to varying degrees. Furthermore, the discussion is tricky, because people easily mix up the semantics of initialization, nullability, and optionality.
It is all the more exciting that non-null refs are now in the status of prototyping for the next version after C# 7 (see https://github.com/dotnet/roslyn/blob/master/docs/Language%20Feature%20Status.md).
Last not least: Several modern programming languages already _have_ null-avoidance features, such as F# (https://docs.microsoft.com/en-us/dotnet/articles/fsharp/language-reference/values/null-values), Swift (https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/swift/grammar/optional-type), or Rust (https://doc.rust-lang.org/std/option/).
There is a pater of 2003 from Microsoft Research: [Declaring and Checking Non-null Types in an Object-Oriented Language] (http://research.microsoft.com/en-us/um/people/leino/papers/krml109.pdf). Unfortunately, the initiative has not been followed through. However, some concepts look quite similar to what later became [NotNull] etc. in ReSharper.
@Vladislav: Yes, non-nullable reference types would make C# more "symmetric" (with nullable value types), which is in itself a good thing from a language design perspective.
As my suggestion has become somewhat popular, I would like to add more context to it. Null references were introduced in ALGOL in 1965. The language designer has famously described this as his "billion dollar mistake" (see
The error has been copied by the mainstream OO languages, inclusign C#. By now, the worldwide costs of preventing and fixing NullReferenceExceptions might easily be in the range of a billion dollars a year.
Given the seriousness of the problem, the correct thing to do would be to redesign C# (or even the .Net Framework) so that, by default, the usage of null is forbidden. To indicate that something might or might not exist, a new "Option<T>" or "Maybe<T>" type could be added, ideally with proper syntactical support in the language. An example of a .Net language who works like this is F#.
However, I don't think it is realistic to expect such a fundamental change in C#, a long-established mainstream language. Therefore, I have suggested the second-best solution, which is to add non-nullable reference types. Of course, this would make C# a bit more complicated, as we would then have four "contingency idioms" (nullable vs. non-nullable value types vs. reference types). But it would still be less complex and expensive than the combined effort of ReSharper/CodeRush, code contracts, coding conventions, documentation, and testing,
while still running the constant risk of NullReferenceExceptions.
498 votesunder review · 15 comments · Visual Studio IDE » Languages - F# Tools · Flag idea as inappropriate… · Admin →
Folders would be nice, or, as an alternative: Improving _object browser_ support in Visual Studio, so that the internal and private details of an F# project can be looked up in a structured way in "My Solution", as it is possible for other languages.
Update: This is still on our short list to add to Visual Studio. Until then, the community-built Visual F# Power Tools extension (https://visualstudiogallery.msdn.microsoft.com/136b942e-9f2c-4c0b-8bac-86d774189cff) remains a great way to get these features.
- David Stephens, Visual F# team