I personally have no problem with the following code
if (Object foo != null && !String.IsNullOrEmpty(foo["bar"]))
{
// do something
}
Because I think the following is too verbose
if (Object foo != null)
{
if (!String.IsNullOrEmpty(foo["bar"]))
{
// do something
}
}
But I wouldn’t go so far with this standpoint if say there were 5 predicates and I had to wrap the text in the editor to see them all at once, is there a logical “line” that you draw as to how many predicates you include in a single if statement in a similar sense to saying that methods should never require more than 7 parameters
I don’t think rewriting if-statements in two is the way, especially if you consider that adding an
elseclause to your examples gives different results. If I wanted to reduce the number of atomic propositions in the condition, I would factor some that make sense together to a function of their own, like: