-
Notifications
You must be signed in to change notification settings - Fork 508
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
Implement SA1131 (UseReadableConditions) #863
Comments
👍 Yoda conditions had their uses in C / C++, but given the strict rules about valid conditions in C#, it no longer makes sense. |
+1 2015-05-18 21:49 GMT+02:00 Vincent Weijsters notifications@github.com:
|
@Przemyslaw-W avoiding |
grabbed. |
I'd like to 👍 the proposal from @Przemyslaw-W to generate a warning when an expression of boolean type is compared to if (completedSuccessfully == true)
if (control.IsVisible == false)
if (dataStorage.GetValue("name") == true)
if ((bool)data[i] == true) |
Im currently working on this. Do we want to report on all occurences of '==' that has a constant value on its left and a non constant value on its right or only built in ones? You could write a non commutative == operator. |
@pdelvo We should assume that operator |
I don't like this rule. I've been coding C/C++/C# for a long time. I've always written my comparisons <constant> == <value>, it's how all my code is formatted. I find it easier to read. The most important term come first. After updating StyleCop I now have to disable this rule in all my projects. |
Just make sure complaining about the comparison to true or false is only for bool and not the bool? data type, where it is valid. |
Category: Readability
Rule: Use readable conditions (alternatively: Do not use Yoda conditions)
Description: The equality and inequality operators
==
and!=
are generally symmetric. In combination with #862, there is no longer a need to write expressions with a literal as the first operand. This rule is described as follows:The text was updated successfully, but these errors were encountered: