Click here to Skip to main content
15,893,814 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.

 
GeneralRe: Multiple returns from methods or clean code flow Pin
CodeWraith15-Feb-19 8:06
CodeWraith15-Feb-19 8:06 
GeneralRe: Multiple returns from methods or clean code flow Pin
charlieg15-Feb-19 17:13
charlieg15-Feb-19 17:13 
AnswerRe: Multiple returns from methods or clean code flow Pin
User 483504715-Feb-19 6:09
User 483504715-Feb-19 6:09 
AnswerRe: Multiple returns from methods or clean code flow Pin
Jörgen Andersson15-Feb-19 6:10
professionalJörgen Andersson15-Feb-19 6:10 
GeneralRe: Multiple returns from methods or clean code flow Pin
OriginalGriff15-Feb-19 6:11
mveOriginalGriff15-Feb-19 6:11 
GeneralRe: Multiple returns from methods or clean code flow Pin
Jörgen Andersson15-Feb-19 6:13
professionalJörgen Andersson15-Feb-19 6:13 
GeneralRe: Multiple returns from methods or clean code flow Pin
Jon McKee15-Feb-19 15:24
professionalJon McKee15-Feb-19 15:24 
AnswerRe: Multiple returns from methods or clean code flow Pin
OriginalGriff15-Feb-19 6:10
mveOriginalGriff15-Feb-19 6:10 
Under most circumstances, a single return is best. But ... I much prefer this:
C#
void MyFunc ()
   {
   if (!ValidateUserInput(ATextBox.Text))
      {
      TellUserAboutTheProblem();
      return;
      }
   if (!ValidateUserInput(AnotherTextBox.Text))
      {
      TellUserAboutTheProblem();
      return;
      }
   ...
   }
To this:
void MyFunc ()
   {
   if (!ValidateUserInput(ATextBox.Text))
      {
      TellUserAboutTheProblem();
      }
   else if (!ValidateUserInput(AnotherTextBox.Text))
      {
      TellUserAboutTheProblem();
      }
   else
      {
      ...
      }
   }
And sometimes the best thing to do is just return, particularly from a nested loop:
C#
for (int i = 0; i < 100; i++)
   {
   for (int j = 0; j < 100; j++)
      {
      if (myArray[i, j] == value) return true;
      }
   }
return false;
Any other mechanism is just making it more complicated, not less.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!

GeneralRe: Multiple returns from methods or clean code flow Pin
Jörgen Andersson15-Feb-19 6:15
professionalJörgen Andersson15-Feb-19 6:15 
GeneralRe: Multiple returns from methods or clean code flow Pin
megaadam17-Feb-19 22:15
professionalmegaadam17-Feb-19 22:15 
GeneralRe: Multiple returns from methods or clean code flow Pin
OriginalGriff17-Feb-19 22:49
mveOriginalGriff17-Feb-19 22:49 
GeneralRe: Multiple returns from methods or clean code flow Pin
megaadam18-Feb-19 2:29
professionalmegaadam18-Feb-19 2:29 
GeneralRe: Multiple returns from methods or clean code flow Pin
André Pereira18-Feb-19 4:42
André Pereira18-Feb-19 4:42 
GeneralRe: Multiple returns from methods or clean code flow Pin
milo-xml18-Feb-19 1:47
professionalmilo-xml18-Feb-19 1:47 
AnswerRe: Multiple returns from methods or clean code flow Pin
lopatir15-Feb-19 6:18
lopatir15-Feb-19 6:18 
GeneralRe: Multiple returns from methods or clean code flow Pin
André Pereira18-Feb-19 4:46
André Pereira18-Feb-19 4:46 
GeneralRe: Multiple returns from methods or clean code flow Pin
lopatir19-Feb-19 1:39
lopatir19-Feb-19 1:39 
AnswerRe: Multiple returns from methods or clean code flow Pin
CodeWraith15-Feb-19 7:05
CodeWraith15-Feb-19 7:05 
AnswerRe: Multiple returns from methods or clean code flow Pin
Gerry Schmitz15-Feb-19 7:33
mveGerry Schmitz15-Feb-19 7:33 
AnswerRe: Multiple returns from methods or clean code flow Pin
ZurdoDev15-Feb-19 7:50
professionalZurdoDev15-Feb-19 7:50 
GeneralRe: Multiple returns from methods or clean code flow Pin
Gerry Schmitz15-Feb-19 8:08
mveGerry Schmitz15-Feb-19 8:08 
GeneralRe: Multiple returns from methods or clean code flow Pin
ZurdoDev15-Feb-19 8:12
professionalZurdoDev15-Feb-19 8:12 
GeneralRe: Multiple returns from methods or clean code flow Pin
CodeWraith15-Feb-19 8:16
CodeWraith15-Feb-19 8:16 
GeneralRe: Multiple returns from methods or clean code flow Pin
ZurdoDev15-Feb-19 8:18
professionalZurdoDev15-Feb-19 8:18 
GeneralRe: Multiple returns from methods or clean code flow Pin
CodeWraith15-Feb-19 8:51
CodeWraith15-Feb-19 8:51 

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.