Two separate "if"'s, same condition -- is it OK?

Viewed 1729

Which of the two, do you think, is better?

if (the_condition)
{
    variable = sth;
}
else
{
    variable = sth_else;
}

if (the_condition)
{
    variable_2.doSth();
}
else
{
    variable_2.doSthElse();
}

or

if (the_condition)
{
    variable = sth;
    variable_2.doSth();
}
else
{
    variable = sth_else;
    variable_2.doSthElse();
}

I ask about it because the second example is obviously shorter. On the other hand in the first example operations on different variables are separated, thus probably easier to read.

Do you consider any of them better? Or is it pointless to ask such a question as it does not matter?

11 Answers
Related