Concise Code (C# Short-Circuit Evaluation)

So, here’s another bothersome code snippet that I came across.  Does the developer think that the intention of their code is clearer with this structure, or do they not understand the short-circuiting behavior of C# (in this case), or is something else at play?

This is the original:

if (!_model.SomeConditionIsTrue())
{
    
if (_model.SomeOtherConditionIsTrue())
    {
        
if (_model.SomeThirdConditionIsTrue())
            ourValue =
true;
    }
    
else
        ourValue =
true;
}
else
    ourValue =
true;

Where I would much prefer to see this more concise version (of course, a descriptive comment would help if the order actually matters):

if (_model.SomeConditionIsTrue() ||
    !_ model.SomeOtherConditionIsTrue() ||
    _ model.SomeThirdConditionIsTrue())
{
    ourValue =
true;
}

Page 11 of 18« First...910111213...Last »
Rss Feed