question of style

Paul Rubin http
Thu Jul 2 21:13:48 CEST 2009


Simon Forman <sajmikins at gmail.com> writes:
> These two snippets of code are functionally identical. Which would you
> use and why?

Both are terrible.  I can't tell what you're really trying to do.  As
Terry Reedy points out, the case where self.higher and self.lower are
both not None is not handled.  If you want to explicitly return None,
use "return None" rather than "return".  Generally, having a special
value like None to denote a missing datum was considered standard
practice a few decades ago, but these days in some circles it's
treated as something of a code smell.  You may want to look for
some other representation instead.

Most importantly, whatever code you write, put in an explanatory
comment saying what the real goal is.



More information about the Python-list mailing list