C
Christian Bau
Christopher Benson-Manica said:Would you suppose that such a view is common in the world of
professional programming? My work experience is still quite limited,
and it's hard to tell ubiquitous programming conventions from
idiosyncratic oddities...
There are different styles. A relatively common one goes like this: At
the start of a function, lots of quick checks for error conditions,
trivial calls, etc. with quick returns. Then the actual work is done,
and there is one single return at the end of the function. Sometimes the
return statement has a label with goto statements going to that label,
sometimes nested if's or multiple if's are used.
Multiple returns within the function body (after the initial quick
checks) can be a huge maintenance problem, if you find out you have to
add some code that needs executing before returning from the function.
People have different styles, and if people tell you "always do X" then
often X is correct 99% of the time, and with some experience you will
know when you run into the 1% when "always do X" is wrong.