
Introducing Nullable Reference Types in C# - benaadams
https://blogs.msdn.microsoft.com/dotnet/2017/11/15/nullable-reference-types-in-csharp/
======
styfle
This is great! TypeScript (another Microsoft language) did something similar
not long ago but used a flag to opt-in to strict null checks. It seems this
setting is strongly encouraged.

Looking at the examples, the compiler can determine if not null by reading the
if statement like so

    
    
        if (str != null)
    

But what about if the code uses the following?

    
    
        if (!string.IsNullOrEmpty(str))
    

TypeScript has a way to solve this using the `is` keyword but I'm not sure if
this is introduced in C# yet.

------
cm2187
I don’t know if it can be called a breaking change but it does feel like this
is a pretty big deal. All your existing solutions are going to start throwing
hundreds of warnings.

In particular these future warnings should be all over everyone’s code:

 _1\. Assigning or passing null to a non-nullable reference type_ : many
functions have non optional arguments and for some actually expect null as an
argument

 _6\. Leaving a nonnullable field of a newly constructed object null after
construction_ : there are many reasons why you may want to populate a field at
a later stage, say you create two objects and you want them to cross reference
each other’s.

It’s basically a fundamental change in the expected behaviour of reference
types.

------
mephitix
This looks a lot like Swift optionals - which to me is a great thing.

I haven't tried this out yet but I also would love to see Swift-like optional
binding (if let...) While it's great if the C# compiler + intellisense could
figure it out I prefer having different vars to differentiate nullability/non-
nullability.

