Too many return-statements = bad style?
Mike at Geary.com
Thu Jul 15 20:31:13 CEST 2004
> Steve Thompson wrote:
> > And for those folks that actually view many exits as a
> > Good Thing, I would argue that increasing the cyclomatic
> > complexity of any piece of code is by definition the very
> > antithesis of good software engineering.
Magnus Lyck? wrote:
> Agreed, but setting a variable to different values in different
> if-else-branches in a function and returning that in a single
> return doesn't give you a lower cyclomatic complexity than
> multiple exits in the if-else-structure.
I'm with you. I've had people take code I wrote that was very clean, simple,
and easy to understand--and yes, used multiple returns--and rewrite it into
a convoluted mess of nested if statements and state variables just to
achieve the holy grail of a single return point. Very frustrating
I can only guess that they saw an early return as adding complexity, but
didn't see nested ifs and extra state variables as adding complexity.
I just want simple, maintainable code, whatever technique gets me there.
More information about the Python-list