Too many return-statements = bad style?

Rgemini roy.OMITTHISBIT.ayres at dsl.pipex.com
Fri Jul 9 08:01:11 EDT 2004


Peter Hansen wrote:
> Pierre-Frédéric Caillaud wrote:
>
>>     I do it just like your style.
>
> So do I.  In addition, though, if the resulting code is still hard to
> read because there is too much between the initial "exceptional"
> returns, and the final return after the else, I would consider
> refactoring so that some of the working code is in a subroutine...
> Then the original function reads much more clearly as what it is:
> a bunch of tests, many of which result in premature failure, and
> then some work and a final return statement.
>
> -Peter

I do it that way too. But I put exit comments next to the returns so they
stand out more. Something like

    return foo    ##### exit because foo = bar #####

Rgemini





More information about the Python-list mailing list