We had a disagreement in a code review.
What I had written:
if(unimportantThing().isGood && previouslyCalculatedIndex != -1)
{
//Stuff
}
if(otherThing().isBad && previouslyCalculatedIndex != -1)
{
//Otherstuff
}
if(yetAnotherThing().isBad)
{
//Stuffystuff
}
The reviewer called that ugly code. This is what he expected:
if( previouslyCalculatedIndex != -1)
{
if(unimportantThing().isGood)
{
//Stuff
}
if(otherThing().isBad)
{
//Otherstuff
}
}
if(yetAnotherThing().isBad)
{
//Stuffystuff
}
I'd say it's a pretty trivial difference and that the complexity of adding another layer of branching is equivalently bad as one or two logical-ands.
But just to check myself, is this really a grievous coding sin that you would take a firm stance over? Do you always pull out the common cases in your if statements and branch on them separately, or do you add logical-ands to a couple of if statements?