6 added syntax-highlighting
source | link
    if(!FileExists(file))
    {
        DefaultAction();
        return;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        DefaultAction();
        return;
    }

    DoSomething(contents);
if(!FileExists(file))
{
    DefaultAction();
    return;
}

contents = OpenFile(file);
if(!SomeTest(contents))
{
    DefaultAction();
    return;
}

DoSomething(contents);
    if(!FileExists(file))
    {
        DefaultAction();
        return Result.FileNotFound;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        DefaultAction();
        return Result.TestFailed;
    }

    DoSomething(contents);
    return Result.Success;            
if(!FileExists(file))
{
    DefaultAction();
    return Result.FileNotFound;
}

contents = OpenFile(file);
if(!SomeTest(contents))
{
    DefaultAction();
    return Result.TestFailed;
}

DoSomething(contents);
return Result.Success;            
Result OurMethod(file)
{
    if(!FileExists(file))
    {
        return Result.FileNotFound;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        return Result.TestFailed;
    }

    DoSomething(contents);
    return Result.Success;            
}

void Caller()
{
    // something, something...

    var result = OurMethod(file);
    // if (result == Result.FileNotFound || result == Result.TestFailed), or just
    if (result != Result.Success)        
    {
        DefaultAction();
    }
}
Result OurMethod(file)
{
    if(!FileExists(file))
    {
        return Result.FileNotFound;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        return Result.TestFailed;
    }

    DoSomething(contents);
    return Result.Success;            
}

void Caller()
{
    // something, something...

    var result = OurMethod(file);
    // if (result == Result.FileNotFound || result == Result.TestFailed), or just
    if (result != Result.Success)        
    {
        DefaultAction();
    }
}
    if(!FileExists(file))
    {
        DefaultAction();
        return;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        DefaultAction();
        return;
    }

    DoSomething(contents);
    if(!FileExists(file))
    {
        DefaultAction();
        return Result.FileNotFound;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        DefaultAction();
        return Result.TestFailed;
    }

    DoSomething(contents);
    return Result.Success;            
Result OurMethod(file)
{
    if(!FileExists(file))
    {
        return Result.FileNotFound;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        return Result.TestFailed;
    }

    DoSomething(contents);
    return Result.Success;            
}

void Caller()
{
    // something, something...

    var result = OurMethod(file);
    // if (result == Result.FileNotFound || result == Result.TestFailed), or just
    if (result != Result.Success)        
    {
        DefaultAction();
    }
}
if(!FileExists(file))
{
    DefaultAction();
    return;
}

contents = OpenFile(file);
if(!SomeTest(contents))
{
    DefaultAction();
    return;
}

DoSomething(contents);
if(!FileExists(file))
{
    DefaultAction();
    return Result.FileNotFound;
}

contents = OpenFile(file);
if(!SomeTest(contents))
{
    DefaultAction();
    return Result.TestFailed;
}

DoSomething(contents);
return Result.Success;            
Result OurMethod(file)
{
    if(!FileExists(file))
    {
        return Result.FileNotFound;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        return Result.TestFailed;
    }

    DoSomething(contents);
    return Result.Success;            
}

void Caller()
{
    // something, something...

    var result = OurMethod(file);
    // if (result == Result.FileNotFound || result == Result.TestFailed), or just
    if (result != Result.Success)        
    {
        DefaultAction();
    }
}
5 replaced http://programmers.stackexchange.com/ with https://softwareengineering.stackexchange.com/
source | link

I'd extract it to a separate method and then:

    if(!FileExists(file))
    {
        DefaultAction();
        return;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        DefaultAction();
        return;
    }

    DoSomething(contents);

which also allows for

    if(!FileExists(file))
    {
        DefaultAction();
        return Result.FileNotFound;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        DefaultAction();
        return Result.TestFailed;
    }

    DoSomething(contents);
    return Result.Success;            

then possibly you could remove the the DefaultAction calls and leave executing the DefaultAction for the caller:

Result OurMethod(file)
{
    if(!FileExists(file))
    {
        return Result.FileNotFound;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        return Result.TestFailed;
    }

    DoSomething(contents);
    return Result.Success;            
}

void Caller()
{
    // something, something...

    var result = OurMethod(file);
    // if (result == Result.FileNotFound || result == Result.TestFailed), or just
    if (result != Result.Success)        
    {
        DefaultAction();
    }
}

I like Jeanne Pindar's approachJeanne Pindar's approach as well.

I'd extract it to a separate method and then:

    if(!FileExists(file))
    {
        DefaultAction();
        return;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        DefaultAction();
        return;
    }

    DoSomething(contents);

which also allows for

    if(!FileExists(file))
    {
        DefaultAction();
        return Result.FileNotFound;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        DefaultAction();
        return Result.TestFailed;
    }

    DoSomething(contents);
    return Result.Success;            

then possibly you could remove the the DefaultAction calls and leave executing the DefaultAction for the caller:

Result OurMethod(file)
{
    if(!FileExists(file))
    {
        return Result.FileNotFound;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        return Result.TestFailed;
    }

    DoSomething(contents);
    return Result.Success;            
}

void Caller()
{
    // something, something...

    var result = OurMethod(file);
    // if (result == Result.FileNotFound || result == Result.TestFailed), or just
    if (result != Result.Success)        
    {
        DefaultAction();
    }
}

I like Jeanne Pindar's approach as well.

I'd extract it to a separate method and then:

    if(!FileExists(file))
    {
        DefaultAction();
        return;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        DefaultAction();
        return;
    }

    DoSomething(contents);

which also allows for

    if(!FileExists(file))
    {
        DefaultAction();
        return Result.FileNotFound;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        DefaultAction();
        return Result.TestFailed;
    }

    DoSomething(contents);
    return Result.Success;            

then possibly you could remove the the DefaultAction calls and leave executing the DefaultAction for the caller:

Result OurMethod(file)
{
    if(!FileExists(file))
    {
        return Result.FileNotFound;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        return Result.TestFailed;
    }

    DoSomething(contents);
    return Result.Success;            
}

void Caller()
{
    // something, something...

    var result = OurMethod(file);
    // if (result == Result.FileNotFound || result == Result.TestFailed), or just
    if (result != Result.Success)        
    {
        DefaultAction();
    }
}

I like Jeanne Pindar's approach as well.

    Post Made Community Wiki by outis
4 added 277 characters in body
source | link

I'd extract it to a separate method and then:

    if(!FileExists(file))
    {
        DefaultAction();
        return;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        DefaultAction();
        return;
    }

    DoSomething(contents);

which also allows for

    if(!FileExists(file))
    {
        DefaultAction();
        return Result.FileNotFound;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        DefaultAction();
        return Result.TestFailed;
    }

    DoSomething(contents);
    return Result.Success;            

then possibly the calleryou could executeremove the the DefaultAction if necessarycalls and leave executing the DefaultAction for the caller:

Result OurMethod(file)
{
    if(!FileExists(file))
    {
        return Result.FileNotFound;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        return Result.TestFailed;
    }

    DoSomething(contents);
    return Result.Success;            
}

void Caller()
{
    // something, something...

    var result = TheAboveMethodOurMethod(file);
    // if (result == Result.FileNotFound || result == Result.TestFailed), or just
    if (result != Result.Success)        
    {
        DefaultAction();
    }
}

I like Jeanne Pindar's approach as well.

I'd extract it to a separate method and then:

    if(!FileExists(file))
    {
        DefaultAction();
        return;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        DefaultAction();
        return;
    }

    DoSomething(contents);

which also allows for

    if(!FileExists(file))
    {
        DefaultAction();
        return Result.FileNotFound;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        DefaultAction();
        return Result.TestFailed;
    }

    DoSomething(contents);
    return Result.Success;            

then possibly the caller could execute the DefaultAction if necessary:

    var result = TheAboveMethod(file);
    // if (result == Result.FileNotFound || result == Result.TestFailed), or just
    if (result != Result.Success)        
    {
        DefaultAction();
    }

I like Jeanne Pindar's approach as well.

I'd extract it to a separate method and then:

    if(!FileExists(file))
    {
        DefaultAction();
        return;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        DefaultAction();
        return;
    }

    DoSomething(contents);

which also allows for

    if(!FileExists(file))
    {
        DefaultAction();
        return Result.FileNotFound;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        DefaultAction();
        return Result.TestFailed;
    }

    DoSomething(contents);
    return Result.Success;            

then possibly you could remove the the DefaultAction calls and leave executing the DefaultAction for the caller:

Result OurMethod(file)
{
    if(!FileExists(file))
    {
        return Result.FileNotFound;
    }

    contents = OpenFile(file);
    if(!SomeTest(contents))
    {
        return Result.TestFailed;
    }

    DoSomething(contents);
    return Result.Success;            
}

void Caller()
{
    // something, something...

    var result = OurMethod(file);
    // if (result == Result.FileNotFound || result == Result.TestFailed), or just
    if (result != Result.Success)        
    {
        DefaultAction();
    }
}

I like Jeanne Pindar's approach as well.

3 added 277 characters in body
source | link
2 added 108 characters in body
source | link
1
source | link