question of style

Terry Reedy tjreedy at udel.edu
Thu Jul 2 14:53:43 EDT 2009


Simon Forman wrote:
> Hey I was hoping to get your opinions on a sort of minor stylistic
> point.
> These two snippets of code are functionally identical. Which would you
> use and why?
> The first one is easier [for me anyway] to read and understand, but
> slightly less efficient, while the second is [marginally] harder to
> follow but more efficient.
> 
> ## First snippet
> 
> if self.higher is self.lower is None: return
> if self.lower is None: return self.higher
> if self.higher is None: return self.lower
> 
> ## Second snippet
> 
> if self.higher is None:
>     if self.lower is None:
>         return
>     return self.lower
> if self.lower is None:
>     return self.higher

What happen is neither is None?




More information about the Python-list mailing list