[nycphp-talk] Question about explicit returns
Daniel Convissor
danielc at analysisandsolutions.com
Sat Jan 12 10:18:00 EST 2008
On Fri, Jan 11, 2008 at 05:23:35PM -0500, Michael B Allen wrote:
> I think the nesting helps you understand the code.
But things get harder to understand if you're nested so far that half of
the code on the line flies off the right hand side of the screen (or
wraps).
Plus to figure out what the code is actually doing you need to jump back
and forth between the appropriate if's and else's. The deeper this gets
the harder this gets.
Then theres the issue of having to read the ENTIRE function in order to
figure out what happens in a given case, even if the function resolves
your issue near the top.
> You know the more
> indented you are the deeper the success of the overall operation.
The same could be said about how many lines down you are into the
function.
> Regarding the number of returns, it's better to minimize the number of
> exit points because it simplifies the function contract. If you have
> to modify the code later, there are fewer exit points to consider.
Yeah, I've heard that point of view before. Sure, you can design only
one exit point but then you have to use more time considering more code
and ensuring all your code doesn't inadvertently change the result before
returning.
Guess our minds work differently. :)
--Dan
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
data intensive web and database programming
http://www.AnalysisAndSolutions.com/
4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409
More information about the talk
mailing list