[bind10-dev] Python style micro-nit

Nathanael Hoyle bind at hoyletech.com
Tue Jun 29 20:46:39 UTC 2010


On 6/29/2010 1:35 PM, Shane Kerr wrote:
> All,
> 
> Something came up in a recent review that Jelte did on some of my code,
> and I'd like to see if there are any preferences.
> 
> In Python you can say:
> 
>     if foo is not None:
>         do_something()
>     if bar not in baz:
>         do_something_else()
> 
> You can also say:
> 
>     if not foo is None:
>         do_something()
>     if not bar in baz:
>         do_something_else()
> 
> Jelte prefers the first style. I have no preference, although I did mix
> them in my code and that's probably a bad thing (although with deep
> thinking one could pick times when it was more important to put the
> "not" first as it was closer to the meaning of the condition, and times
> when it was important to put the "not" later).
> 
> Any other preferences? Is this important enough to even document?
> 
> --
> Shane
> 
> _______________________________________________
> bind10-dev mailing list
> bind10-dev at lists.isc.org
> https://lists.isc.org/mailman/listinfo/bind10-dev

Personally, I have always used the former style, and strongly prefer it.
It reads "naturally" which I believe is one of the key strengths of
Python as a language (indeed, otherwise one could just use things like
"==" as opposed to "is"). The boolean algebra equivalence doesn't make
the latter any easier to read. Since I'm not really a bind 10 developer
per se, I realize my 2 cents may not be worth much, but I've found the
former style to be quite predominant among those who write a lot of
Python. Not having a standard wouldn't trip me up too much, since it's
not that hard to figure out the latter style, but I would personally
have a very hard time forcing myself to write the latter style
consistently if that were the standard.

-Nathanael




More information about the bind10-dev mailing list