Too many return-statements = bad style?

Andrei project5 at redrival.net
Fri Jul 9 15:37:36 CEST 2004


Marco Aschwanden <PPNTWIMBXFFC <at> spammotel.com> writes:

> I checked the other day  a module of mine with pylint. And for some 
> function it told me, that I was using too many return-statements in my 
> code... there were about 5 or 7 of them in my function.
<snip>

I prefer multiple returns instead of increasingly complex nesting. Obviously
having too many returns (or too much nesting) is showing that you've got a
function which is in need of splitting - I think 5 and especially 7 is a lot,
but it depends on the function. I also like having the conditions such, that the
short code is at the top of the if-else clause, while some programming
guidelines claim you should write the most common cause first (even if that's
considerably longer than the uncommon one).

Yours,

Andrei






More information about the Python-list mailing list