Rafael said:
jameskuyper escreveu:
Sorry, but I don't think I get the "early return" meaning...
What should I do? Write more fake code?
Let me clarify what I'm referring to by re-writing your code in the
"pure" style:
int main(int argc, char **argv)
{
char *whatever;
int retval = EXIT_SUCCESS;
if( (whatever = strdup(whatothereverchar))==NULL)
retval = docomplain();
else
{
/*handle whatever*/
free(whatever);
}
return retval;
}
The relevant mantra says that there shall always be only one exit
point from a function. This is supposed to make it easier to
understand the control flow of the function, and as result, make it
easier to avoid or detect incorrect control flow. While I understand
the point being made, I'm not fully in agreement with the proposed
solution. As is typical, re-writing to have only one exit point made
this code somewhat more complicated. It required addition of a named
variable, the creation of an else{} block, and a corresponding
indentation of the code in that block. In my experience, the extra
indentation is the biggest problem, because too much indentation can
render a function of only moderate size virtually unreadable. I
normally indent by 4 spaces; you seem to prefer 2 spaces, which makes
excess indentation less of a problem, but at the expense of making the
indentation harder to notice.
These disadvantages cancel out some of the supposed benefits of this
style.