On nullability and null checking #3205
dodexahedron
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
And for argument validation, there are the |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Just a general comment for code in the project, when null checks are performed.
If you are explicitly checking for or against
null
, you should use either theis null
oris { }
patterns.Why?
operator==
can be overloaded. Theis
operator cannot. Therefore, theis
operator will ALWAYS be a check against null, whereasx == null
is not a guarantee, at the call site.Plus, that comes with some syntactic goodies like being able to do a check and an assignment in one line, such as:
That's a null check and, if not null, assignment to x, for later use, at the same scope as the if statement (so not just within the brackets).
Just something to be aware of.
Beta Was this translation helpful? Give feedback.
All reactions