I know that I'm a little late to the party. But this whole opt-in/compatibility approach seems awfully verbose to me. Wouldn't it be possible to just make a compiler switch? That way we'd have a non verbose way to go forward - and legacy projects can just flip a switch to turn off all the null-checking by the compiler.
Think about it: If you think non-nullable reference types are good thing (that includes me), you'll use them everywhere. If not, you don't use them at all. Now the first kind would need to spam ! everywhere, and that's just ugly, tedious and error prone. So why not just a compiler switch on the project? On means we treat string as a non-nullable reference type (or string!) and off is the way we have it now. Off just disables all null checking when compiling.
The only problem with the compiler switch that I can think of is the compatibility between libraries. But if a library was compiled with the nullable flag off, a method that returns a string would be treated as a method that returns a string?. The other way round, we would still have to rely on ArgumentNullExceptions, but that is consistent with the way that we live now (in a nullable = off world).
Is that a realistic alternative to the ! spamfest?
What makes you think the C# team is going forward with the ! approach? The latest proposal we've seen here had an assembly-level attribute that turned reference types non-nullable to the compiler and to any consumers with the same attribute. Or was something different demoed on Build?
@luetm This fair concern had been raised very early.
@orthoxerox to be fair it's not obvious at all what is the current design of this feature and whether it will make it into C#7.
@orthoxerox,
Would it not be more helpful to guide @luetm (and others reading this) to "The latest proposal we've seen here"?
@DavidArno It's as easy as entering "non-nullable" into the search field and looking for the most popular recent issue, i.e. #7445
@orthoxerox,
Sure. one can do a search. And that'll give you a thread with the last comment from the beginning of Feb. Whereas eg #2136-comment shows that as of 11 days ago, it is very likely that non-nullable reference types won't show until C#8+ (and so the syntax/implementation may end up being very different).
It is extremely difficult to find the latest info on most things around C# 8 at the moment. Github's issue system isn't really suitable for tracking such things and a lot of discussion/decisions still go on behind the scenes at Microsoft. So, IMO at least, we should really be trying to help each other find info as easily as possible, rather than taking the "do a search" stance.
There's also the _Language Feature Status_ page in the repo from 3 days ago, which confirms that non-nullable types are planned for C# 8. (Here's hoping it will stay up to date.)
Duplicate of #7445