Too many return-statements = bad style?

Peter Hansen peter at engcorp.com
Fri Jul 9 12:50:54 CEST 2004


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



More information about the Python-list mailing list