I'm having an internal dispute about the right way to do something. Maybe you can help :)
Let's say I have the functions
foo(x, y)
{
if (x satisfies condition c1)
if (y satisfies condition c2)
bar(x)
else
bar(x)
...
}
bar(x)
{
...
}
An alternative to this would be
foo(x, y)
{
doBarFlag = false
if (x satisfies condition c1)
if (y satisfies condition c2)
doBarFlag = true
else
doBarFlag = true
if (doBarFlag)
{
...code from bar() goes in here
}
...
}
And another alternative (slight variation of above)
foo(x, y)
{
doBarFlag = true
if (x satisfies condition c1)
if (y DOES NOT satisfy condition c2)
doBarFlag = false
if (doBarFlag)
{
...code from bar() goes in here
}
...
}
Assume that bar() is less than ten lines. Which style would you prefer? Why? I'm leaning toward the first example, but I'd like to know what others think.