-
Notifications
You must be signed in to change notification settings - Fork 786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remove Debug.Assert null checks #6101
base: main
Are you sure you want to change the base?
remove Debug.Assert null checks #6101
Conversation
I don't agree with this direction. Always best practice to validate your assumptions! A simple |
but those assumptions are validated by the compiler also the debug check for null pattern is not consistently applied the majority of internal methods do not apply this pattern. and many methods only apply it on a subset of parameters |
also the “always validate your assumptions” argument doesn’t hold water when u consider we are only validating in a debug build. none of the code i removed has any effect on the deployed release build. lets take the scenario where one of the nullability assumptions is incorrect (ie the compiler has a bug or code is being executed with relection). we will only get the null check behaviour in a local debug build when running tests. not in CI or prod. now if we remove the debug checks. the result in a local debug test run will be a nice stack trace with a line number pointing to the null variable |
Changes
So i suspect the Debug.Assert null checks pre-date nullability. IMO with nullability they are redundant. essentialy for public APIs we should guard agains null with ArgumentNullExceptions, for non public APIs we should rely on the compiler for nullability checks
this also has the side effect of allow us to remove 100+ null suppressions. the reason being that in a debug build, if u do a
Debug.Assert(variable != null
then the compiler wants u to suppress nulls for all all subsequent usages of that variableMerge requirement checklist
CHANGELOG.md
files updated for non-trivial changes