You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The dreaded NullReferenceException comes from a mistake by the legendary Tony Hoare in 1966, and he has since apologized for it. But most languages have, nevertheless, inherited this mistake.
.NET doesn't provide a real solution at the type level to fully eliminate them, but with the latest .NET versions if you turn on nullable types you can come pretty close to solving this class of problems entirely at compile-time.
And we can do it with confidence that we aren't breaking anything with the following process:
Set <Nullable>enable</Nullable> on a selected project
Put #nullable disable on the top of every code file
Remove that line from the previous step on a file-by-file basis, and modify each file by affixing ? modifiers accordingly.
If enough progress is made we can simply move the <Nullable>enable</Nullable> setting into Directory.Build.props and have it be set for every project in the solution.
I have been looking for a solution that can just automatically add nullability modifiers in a dumb way, which replicates existing nullability guarantees. Haven't found anything.
But, given that it isn't really enforced at the type level, if it compiles then it is going to work as before.
The text was updated successfully, but these errors were encountered:
I say that it isn't real because when you turn on nullable types, a variable that is declared without a ? modifier is actually still fully capable of holding a null value, such as when it is a public function and referenced from code that doesn't have nullable types turned on. Because it is all just akin to fancy analyzers, rather than part of the type system.
But far, far, better than nothing. And also, there's yet more analyzers that warn you about unguarded use of non-nullable parameters of public functions.
The dreaded NullReferenceException comes from a mistake by the legendary Tony Hoare in 1966, and he has since apologized for it. But most languages have, nevertheless, inherited this mistake.
.NET doesn't provide a real solution at the type level to fully eliminate them, but with the latest .NET versions if you turn on nullable types you can come pretty close to solving this class of problems entirely at compile-time.
And we can do it with confidence that we aren't breaking anything with the following process:
<Nullable>enable</Nullable>
on a selected project#nullable disable
on the top of every code file?
modifiers accordingly.If enough progress is made we can simply move the
<Nullable>enable</Nullable>
setting into Directory.Build.props and have it be set for every project in the solution.I have been looking for a solution that can just automatically add nullability modifiers in a dumb way, which replicates existing nullability guarantees. Haven't found anything.
But, given that it isn't really enforced at the type level, if it compiles then it is going to work as before.
The text was updated successfully, but these errors were encountered: