3 ms·
You're describing C# as it was before nullability tracking. For several years now, it does have a mode in which every reference that can be null must be explici
by int_19h 4y ago
You're describing C# as it was before nullability tracking. For several years now, it does have a mode in which every reference that can be null must be explicitly checked to be non-null first before you can use it, very similar to Kotlin.
https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references#null-state-analysis https://learn.microsoft.com/en-us/dotnet/csharp/nullable-ref...
So yes, "will require you to properly handle them" is exactly what I meant.
- Someone 4y agoFTA, emphasis added: “Nullable reference types refers to a group of features enabled in a nullable aware context that _minimize_ the likelihood that your code causes the runtime to throw System.NullReferenceException.” That approximates it, and likely gives you most of the benefits, but it isn’t the same as strict enforcement of necessary null checks. There will be cases where the programmer can prove a value isn’t null, but the compiler can’t, and thus, the programmer can choose to ignore the warning. That’s similar to how Java tries to prove that a variable is initialized when being read. (https://docs.oracle.com/javase/specs/jls/se9/html/jls-16.html https://docs.oracle.com/javase/specs/jls/se9/html/jls-16.htm...). Java makes the safe choice, though. It refuses to compile such programs, thus guaranteeing that every local variable and blank final field will be initialized before first use.
- int_19h 4y agoThat's exactly why I asked for specific examples of when nullable enforcement does not catch a potential null reference at compile time. I can't think of any such case so long as all the code has it enabled (if not, it's like safe Rust calling into unsafe). And if you ignore the warnings, that's a deliberate opt-out; why even bother with nullability checks then?