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

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

 



At 3:25 PM +0100 6/29/08, Colin Guthrie wrote:
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

Whenever possible, I try to keep to a single return in my functions. For me it usually makes my life easier.

However, there are times that if one insists on keeping to a single return doctrine, then the code can become very difficult to read because of additional code to maintain the requirement.

I found an excellent example of this in DOM Scripting (page 99) by Keith where he takes a sea of curly braces and reduces them down a few false returns that appear immediately at the beginning of the function.

So, in this case I clearly support multiple returns provided that they appear in a logical and obvious location (i.e., in the front of the function).

Having multiple returns spread throughout a function is not conducive to providing the reader with easy comprehension as to what the function is doing (i.e., readability) -- which is the main reason for all of this concern anyway.

When you can easily understand what your function is doing by inspection, then you are doing something right.

Cheers,

tedd

PS: Nice try on the starting another thread.  :-)

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
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