Which syntax is better for return value?

Posted by Omar Kooheji on Stack Overflow See other posts from Stack Overflow or by Omar Kooheji
Published on 2008-09-26T14:09:28Z Indexed on 2010/04/04 5:23 UTC
Read the original article Hit count: 380

Filed under:
|

I've been doing a massive code review and one pattern I notice all over the place is this:

public bool MethodName()
{
    bool returnValue = false;
    if (expression)
    {
        // do something
        returnValue = MethodCall();
    }
    else
    {
        // do something else
        returnValue = Expression;
    }

    return returnValue;
}

This is not how I would have done this I would have just returned the value when I knew what it was. which of these two patterns is more correct?

I stress that the logic always seems to be structured such that the return value is assigned in one plave only and no code is executed after it's assigned.

© Stack Overflow or respective owner

Related posts about coding-style

Related posts about return-value