PEP 285: Adding a bool type

Steve Holden sholden at holdenweb.com
Fri Apr 5 16:22:23 EST 2002


"Gustavo Niemeyer" <niemeyer at conectiva.com> wrote ...
> > Arguably, most of that code should have read
> >
> >     if ret:
> >         ...
> >
> > rather than
> >
> >     if ret == None:
> >         ...
> >
> > since the latter has the flavor of "if expr==True".
> >
> > So, is breaking bad code more excusable than breaking good code ;-)?
>
> It should be "if not ret", and most of the time this is a matter of
> taste (some times you just have to do this, since you want to check for
> "None", and not for 0). Nevertheless, this is a valid construct, and
> not uncommon (indeed, I have no problems with this). If you don't
> like this, don't use for yourself, but language design is much more than
> "I don't like this so everyone using it should burn".
>
I certainly don't remember making any suggestion that required programmer
combustibility, and I take your point (and agree with it) entirely.

*My* point, however badly I originally made it, was that writing

    if ret == None:

is *sometimes* like writing

    if (a == 3) == True:

assuming this new wart appears in Python. Clearly there are cases where an
explicit test for None (or [], or some other value treated as false) is
required. Equally clearly there are places where the explicit test can be
omitted, and where it can be omitted it usually should be.

I believe I already pointed out myself that it should be "if not ret". Makes
no essential difference to my argument (apart from being correct instead of
incorrect :-).

regards
 Steve







More information about the Python-list mailing list