Re: Re: Early return (was: Inspiration for a Tombstone.)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 2008-06-29 at 17:47 +0300, Dotan Cohen wrote:
> 2008/6/29 Colin Guthrie <gmane@xxxxxxxxxxxxxx>:
> > Dotan Cohen wrote:
> >>
> >> Why not? I do this often, but I am not a professional programmer. I
> >> find this to be very useful.
> >
> > Found another opinion/article about this. I remember reading this one a
> > while back:
> >
> > http://whatimean.wordpress.com/2007/02/08/multiple-return-points-are-bad/
> >
> > Like I said before, I don't personally subscribe to this point of view, but
> > it makes for interesting reading :D
> >
> 
> Thanks. He makes a good point. For my own one-man-show homepage, my
> multile-exit strategy is fine. But I do see the value in regard to
> code debugging and following the code flow.

I'm a big fan of multiple early returns whenever possible, but once the
code becomes more complex holding back until the end if possible. I find
multiple early returns are very easy to read and then the purpose of the
code doesn't get lost within the convolution of the logic. Similarly, I
use the exact same approach with a loop from which I want to
break/continue. I find it much clearer to see at the very beginning of a
function or loop block exactly what easily fails to meet the criteria
and is discarded early. Additionally, this makes the code more linear in
that far fewer nestings are required. From that I'd argue that the more
linear the code is, the more readable and understandable it is.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux