I'm wondering if there has been any research (both casual and robust) on the maintainability of projects that use the "guard statement" paradigm vs. the "single function exit point" paradigm?
Guard statement example (in C#):
string GetSomeString()
{
if(necessaryConditionFails) { return null; }
if(!FunctionWithBoolReturn(someAttribute)) { return null; }
//all necessary conditions have been met
//do regular processing...
return finalStringValue;
}
single function exit point example (in C#):
string GetSomeString()
{
string valueToReturn = null;
if(necessaryConditionPasses && FunctionWithBoolReturn(someAttribute))
{
//all necessary conditions have been met
//do regular processing...
valueToReturn = finalStringValue;
}
return valueToReturn;
}
I know the merits and failings of both have been debated endlessly on SO, but I'm looking for actual research into how maintainable each paradigm is*. This may be unknown, but I figured if the information is out there, someone on SO would know where it was. My web searches have not been sucessful so far.
*I'm also aware that many programmers (including me) use both principals throughout their code, depending on the situation. I'm just hoping to discover which one has a proven track record of greater maintainability to use as the preferred paradigm.