I often come across patterns like this in my company's code:
{
bool result = true;
... some code which may set result to false.
if ( result == ok)
{
... remainder of function, now indented one level further
}
else
{
report an error
}
...
return result;
}
Perhaps a former developer came to C++ from Pascal where only one return point is possible.
This makes me wish there was a Visual Assist refactoring "Reverse logic of if statement" which would allow me to click on the 'if' and turn it automatically into
if (!(result == ok))
{
report an error
}
else
{
... remainder of function, now indented one level further
}
I would then still want to manually edit this to
if (result != ok)
{
report an error
return false;
}
... remainder of function, now NOT indented one level further
But at least the refactoring tool could help me move things into the right order.