On Sunday 07 June 2009 21:39:44 James Courtier-Dutton wrote:
> I would aim for a function to have a single entry point and a single
> exit point with goto's used on the error paths. I.e. the Linux kernel
> style.
I tend to aim for a single exit point as well, with the caveat that
readability trumps ideals.
If there're some trivial cases (e.g., invalid inputs or a cached result)
followed by a complex case (in the case of Hugo's example), then I'd
tend to go for A, since:
* It makes it obvious that the trivial cases don't rely on
any of the complex code.
* It allows people to ignore the trivial cases and treat the
complex code as a single standalone block when they're trying
to figure out what it's doing.
If all the code paths are complex, then a single point of exit
provides a single place to verify/filter/debug the result.
For a language such as Java, which has exception handling,
exceptions may be thrown at any point, effectively giving
multiple exits anyway.
--
Be seeing you, http://www.glendale.org.uk
Sam. Mail/IM (Jabber): sam@???