Robert Cummings wrote:
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.
I think you've captured very eloquently exactly how I feel about this!
I've often thought that the if you disagree about early return then you
automatically have to hate the whole continue/break thing too when used
in loops - basically language *features*. I do concede (as you do) that
there are times when the code benefits from nesting rather than "early
return/break/continue/exit".
Col
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php