Not sure about that. In some cases I have seen so far, there were quite a number of elseifs. My goal was to get out of the function as soon as possible - continuing to iterate through all the cases you already know won't apply doesn't seem like a good use of resources to me.

I also don't think that part of it was controversial - it was more about that up until now, returns were in general either at the start or end of a function and what I introduced used some more in the middle of a function. So in your example, you would still kinda-sorta hunt for where the $return is set in the first place.

-David


On Thu, Sep 5, 2013 at 10:58 AM, taki <taki@alkoholista.hu> wrote:
2013-09-03 00:14 időpontban David Deutsch ezt írta:


"Roundcube, code proudly cleant by argumenting trolls"

For what it's worth, I found it pretty funny, so: I'll take it! ;-)

For that specific "entire content of a function" case I mentioned the exceptions that allow returns at the beginning of a function that check preconditions.

True, and that is indeed a good example that you're citing. I still think my version is easier to understand, but hey - I did the work on it, so it might as well just be confirmation bias ;-)

I think that the maybe-best implementation is:

function foo()
{
    $return = null;

    if (expr)
    {
        [...]
        $return = $something;
    }

    return $return;
}

--
Takika

_______________________________________________
Roundcube Development discussion mailing list
dev@lists.roundcube.net
http://lists.roundcube.net/mailman/listinfo/dev