Click here to Skip to main content
14,638,468 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
TylerMc00718-Feb-19 5:52
MemberTylerMc00718-Feb-19 5:52 
AnswerRe: Multiple returns from methods or clean code flow Pin
MSBassSinger18-Feb-19 7:55
professionalMSBassSinger18-Feb-19 7:55 
GeneralRe: Multiple returns from methods or clean code flow Pin
BillWoodruff19-Feb-19 15:28
mveBillWoodruff19-Feb-19 15:28 
GeneralRe: Multiple returns from methods or clean code flow Pin
MSBassSinger19-Feb-19 15:34
professionalMSBassSinger19-Feb-19 15:34 
AnswerRe: Multiple returns from methods or clean code flow Pin
SeattleC++18-Feb-19 12:13
MemberSeattleC++18-Feb-19 12:13 
AnswerRe: Multiple returns from methods or clean code flow Pin
frazGJF18-Feb-19 18:08
MemberfrazGJF18-Feb-19 18:08 
AnswerRe: Multiple returns from methods or clean code flow Pin
BillWoodruff19-Feb-19 0:45
mveBillWoodruff19-Feb-19 0:45 
AnswerRe: Multiple returns from methods or clean code flow Pin
S.Donovan19-Feb-19 3:03
professionalS.Donovan19-Feb-19 3:03 
Single ``return`` or multiple ``return`` I think is a potential code smell - based on design and code format agreements.

I like the concept of having the guard statements and their ``return`` or ``throw`` exception small and tight at the beginning of a function/method. Putting the error handling into an ``else`` block can destroy the readability.

We recently found a method in a work project where we were setting a ``results`` variable to ``true``, and then calling ``return false``. The last line of the method was to ``return results``. (Of course, no comments what team member that is no longer with the company was thinking.) This was in the logic and processing, not in guard statements.

I think using negation logic can also be a code smell
void doSomething(var a)
{
    if (a == null)
    {
        throw new Exception("a == null");
        // or return with no meaningful "why"
    }
    else
    {
        //...
    }
}

is more readable than
void doSomething(var a)
{
    if (a != null)
    {
        //...
        // Many lines so that the error handling is separated from the test
        //...
    }
    else
    {
        throw new Exception("a == null");
        // or return with no meaningful "why"
    }
}

AnswerRe: Multiple returns from methods or clean code flow Pin
Kirk 1038982119-Feb-19 7:32
MemberKirk 1038982119-Feb-19 7:32 
GeneralThought of the Day Pin
OriginalGriff15-Feb-19 4:50
mveOriginalGriff15-Feb-19 4:50 
GeneralRe: Thought of the Day Pin
User 483504715-Feb-19 5:05
MemberUser 483504715-Feb-19 5:05 
GeneralRe: Thought of the Day Pin
lopatir15-Feb-19 5:09
Memberlopatir15-Feb-19 5:09 
GeneralRe: Thought of the Day Pin
dandy7215-Feb-19 5:36
Memberdandy7215-Feb-19 5:36 
GeneralRe: Thought of the Day Pin
  Forogar  15-Feb-19 5:37
professional  Forogar  15-Feb-19 5:37 
GeneralRe: Thought of the Day Pin
Rajesh R Subramanian15-Feb-19 9:15
professionalRajesh R Subramanian15-Feb-19 9:15 
GeneralRe: Thought of the Day Pin
dandy7216-Feb-19 5:53
Memberdandy7216-Feb-19 5:53 
GeneralRe: Thought of the Day Pin
Rajesh R Subramanian18-Feb-19 1:24
professionalRajesh R Subramanian18-Feb-19 1:24 
GeneralRe: Thought of the Day Pin
megaadam15-Feb-19 5:42
professionalmegaadam15-Feb-19 5:42 
GeneralRe: Thought of the Day Pin
jeron115-Feb-19 6:11
Memberjeron115-Feb-19 6:11 
GeneralRe: Thought of the Day Pin
lopatir15-Feb-19 6:28
Memberlopatir15-Feb-19 6:28 
GeneralRe: Thought of the Day Pin
jeron115-Feb-19 6:33
Memberjeron115-Feb-19 6:33 
GeneralRe: Thought of the Day Pin
Mike Hankey15-Feb-19 7:47
professionalMike Hankey15-Feb-19 7:47 
GeneralRe: Thought of the Day Pin
DRHuff15-Feb-19 10:27
MemberDRHuff15-Feb-19 10:27 
GeneralToday is a good day Pin
Sander Rossel15-Feb-19 4:07
professionalSander Rossel15-Feb-19 4:07 
GeneralRe: Today is a good day Pin
Mark Parity15-Feb-19 4:24
MemberMark Parity15-Feb-19 4:24 

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.