Click here to Skip to main content
15,893,401 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
AnswerRe: Multiple returns from methods or clean code flow Pin
User 1106097915-Feb-19 8:25
User 1106097915-Feb-19 8:25 
AnswerRe: Multiple returns from methods or clean code flow Pin
Rajesh R Subramanian15-Feb-19 9:11
professionalRajesh R Subramanian15-Feb-19 9:11 
AnswerRe: Multiple returns from methods or clean code flow Pin
Slacker00715-Feb-19 10:19
professionalSlacker00715-Feb-19 10:19 
AnswerRe: Multiple returns from methods or clean code flow Pin
Mark_Wallace15-Feb-19 10:27
Mark_Wallace15-Feb-19 10:27 
AnswerRe: Multiple returns from methods or clean code flow Pin
Tim Deveaux15-Feb-19 12:18
Tim Deveaux15-Feb-19 12:18 
GeneralRe: Multiple returns from methods or clean code flow Pin
Mark_Wallace15-Feb-19 12:53
Mark_Wallace15-Feb-19 12:53 
GeneralRe: Multiple returns from methods or clean code flow Pin
Tim Deveaux15-Feb-19 13:26
Tim Deveaux15-Feb-19 13:26 
AnswerRe: Multiple returns from methods or clean code flow Pin
Marc Clifton15-Feb-19 13:08
mvaMarc Clifton15-Feb-19 13:08 
It's an old lesson I learned, probably from the days of assembly -- always have one point of return, mainly for consistent stack cleanup. I do rarely make an exception (to that rule) but usually end up making some other change that removes the if.

If you're doing parameter checking, as in your example, I tend to think it's better to throw an exception -- why should the function that's being called expect anything but valid parameters?

I've seen return sprinkled throughout a function as part of the flow control. I hate that. Sometimes I don't see the return, set the breakpoint at the end of the function, and then have to steps through from the top and realize some moron tossed in an early return. I'd almost rather they use a goto to the return, haha.

Personally, I look at code like that and refactor it into smaller functions that have no if statements, and the flow control occurs in a higher level function that doesn't do anything but call other functions based on conditions of previous functions or the data values. A lot more readable too when you separate out the flow control from the individual activities of each flow.
Latest Article - Slack-Chatting with you rPi

Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny

Artificial intelligence is the only remedy for natural stupidity. - CDP1802

GeneralRe: Multiple returns from methods or clean code flow Pin
BillWoodruff19-Feb-19 14:11
professionalBillWoodruff19-Feb-19 14:11 
AnswerRe: Multiple returns from methods or clean code flow Pin
charlieg15-Feb-19 17:21
charlieg15-Feb-19 17:21 
AnswerRe: Multiple returns from methods or clean code flow Pin
Member 916705717-Feb-19 20:42
Member 916705717-Feb-19 20:42 
AnswerRe: Multiple returns from methods or clean code flow Pin
Delphi.7.Solutions17-Feb-19 21:52
Delphi.7.Solutions17-Feb-19 21:52 
GeneralRe: Multiple returns from methods or clean code flow Pin
kalberts18-Feb-19 0:34
kalberts18-Feb-19 0:34 
GeneralRe: Multiple returns from methods or clean code flow Pin
Delphi.7.Solutions18-Feb-19 3:30
Delphi.7.Solutions18-Feb-19 3:30 
GeneralRe: Multiple returns from methods or clean code flow Pin
Richard Deeming18-Feb-19 2:08
mveRichard Deeming18-Feb-19 2:08 
AnswerRe: Multiple returns from methods or clean code flow Pin
Davyd McColl17-Feb-19 22:18
Davyd McColl17-Feb-19 22:18 
AnswerRe: Multiple returns from methods or clean code flow Pin
_WinBase_17-Feb-19 22:36
_WinBase_17-Feb-19 22:36 
AnswerRe: Multiple returns from methods or clean code flow Pin
megaadam17-Feb-19 22:47
professionalmegaadam17-Feb-19 22:47 
AnswerRe: Multiple returns from methods or clean code flow Pin
kalberts18-Feb-19 0:21
kalberts18-Feb-19 0:21 
AnswerRe: Multiple returns from methods or clean code flow Pin
Jeroen_R18-Feb-19 1:38
Jeroen_R18-Feb-19 1:38 
AnswerRe: Multiple returns from methods or clean code flow Pin
Michael Breeden18-Feb-19 2:00
Michael Breeden18-Feb-19 2:00 
AnswerRe: Multiple returns from methods or clean code flow Pin
Peter R. Fletcher18-Feb-19 3:18
Peter R. Fletcher18-Feb-19 3:18 
AnswerRe: Multiple returns from methods or clean code flow Pin
obermd18-Feb-19 4:30
obermd18-Feb-19 4:30 
AnswerRe: Multiple returns from methods or clean code flow Pin
SpiritualMadMan18-Feb-19 4:54
SpiritualMadMan18-Feb-19 4:54 
AnswerRe: Multiple returns from methods or clean code flow Pin
Martin ISDN18-Feb-19 5:15
Martin ISDN18-Feb-19 5:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.