Re: single return from function

Keith Ray <[email protected]> Thu, 15 Nov 2012 19:39:38 -0800
Newsgroups gmane.comp.programming.refactoring
Message-ID <[email protected]>
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).
> 
> Is that true?
> 
> I couldn't find it anywhere in the online catalog.
> 
> Thanks!
> 
> * see item 8 (might change)
> http://www.javalobby.org/forums/thread.jspa?forumID=61&threadID=16937
> 
> 



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