-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Use is operator for null check instead of == #16035
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh no. Why change 800 files for this? :) I had some discussion with somebody for a line changed somewhere under a PR, but that's one thing, changing every instance in the codebase is another ballpark.
What's the benefit, exactly? How does it enhances readability and reduces the change of null-related bugs? Is dashboardFeature is null
really more readable than dashboardFeature == null
when we use ==
and !=
for every other equality check, and have all C-type languages since the dawn of time? Can you provide some evidence of the benefit?
Pattern matching is great, but there is no "pattern" here to match. All these changes are just literal ==
-> is
and !=
-> is not
changes (and FWIW, I've seen actual use cases for pattern matching missed in there where the expression was longer).
is and is not much readable & cleaner for |
Please reply to this:
|
To be honest, the JIT ASM for both are the same, but for the readers |
Maybe you should be more of a C# guy ;). |
Have a look at the examples below: int i = 1;
if (i is null)
{
Console.WriteLine("i is null");
} this will not compile because int i = 1;
if (i == null)
{
Console.WriteLine("i is null");
} it will compile and the condition is Think for this and you will know what I mean :) |
That's a good point, but since this PR compiles, it doesn't apply to any of the changes in it. The second example also emits this warning BTW, that in our case still breaks the build: https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs0472?f1url=%3FappId%3Droslyn%26k%3Dk(CS0472) |
I didn't understand which build had been broken. |
If you write the second example, it causes a build warning. This will fail the CI build. |
@hishamco I also agree that this isn't needed. Also today @sebastienros said this isn't needed. Maybe we should not then? |
No problem, we could close it then :) |
Enhance readability and reduces the chance of null-related bugs