I keep hearing people talk about how non-nullable reference types would solve so many bugs and make programming so much easier. Even the creator of null calls it his billion
I admit that I haven't really read a lot about Spec#, but I had understood that the NonNullable was essentially an attribute that you put on a parameter, not necessarily on a variable declaration; Turn your example into something like:
class Class { ... }
void DoSomething(Class c)
{
if (c == null) return;
for(int i = 0; i < c.count; ++i) { ... }
}
void main() {
Class c = nullptr;
// ... ... ... code ...
DoSomething(c);
}
With Spec#, you are marking doSomething to say "the parameter c cannot be null". That seems like a good feature to have to me, as it means I don't need the first line in the DoSomething() method (which is an easy to forget line, and completely meaningless to the context of DoSomething()).