Re: single return from function

Jeff Langr <[email protected]> Thu, 15 Nov 2012 22:21:10 -0700
Newsgroups gmane.comp.programming.refactoring
Message-ID <CAO5C3tfyqKeHsekgVjrsiXk=1HseqOM30P9UUiAx8C_4Zn47DA@mail.gmail.com>
On Thu, Nov 15, 2012 at 8:39 PM, Keith Ray <[email protected]> wrote:

> I don't think the Refactoring book makes that recommendation. That advice
> dates back to "structured programming" (google it).
>
> In a long function, multiple returns are hard to see, and may require
> duplicated code. In less smelly code, after refactoring, a function is
> typically less than 10 lines long, and could have a few early returns (see
> "guard clause") in addition to the final return statement.
>
> On 2012 Nov 15, at 6:09 PM, alex_us01 wrote:
>
> > On the internet, I found somewhere* that the Refactoring book advocates
> for a single return from a function (thus, promoting assigning values to a
> variable, such as result, and then say return result; at the end).
>

Keith is spot on.

I have a slightly amusing story about hearing that "rule" a couple times at
the same place in the space of a few days:
http://langrsoft.com/jeff/2011/10/dont-stop-reading/

Jeff

Langr Software Solutions
http://langrsoft.com
http://agileinaflash.com - Agile in a Flash: A top 20 agile book! (
http://www.noop.nl/2010/08/top-100-agile-books.html)


[Non-text portions of this message have been removed]



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/refactoring/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/refactoring/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/