Debugging flags [was: Re: PEP 285: Adding a bool type]

Steve Holden sholden at holdenweb.com
Mon Apr 1 08:05:24 EST 2002


"phil hunt" <philh at comuno.freeserve.co.uk> wrote ...
[...]
> I've gone through some of my herbivore code, looking to see where
> I've used 0 or 1 as a boolean. Example 1:
>
> debug = 0  # debugging this module?
>
> Frankly, if that is unclear to anyone, they are not cut out to be a
> programmer. Bear in mind that most non-programmers are aware of the
> 0/1 paradigm for boolean values: it appears on much electrical
> equipment.
>
I find it much more helpful to use

    debug = (1, 2, 7, 93) # debugging parsing, tree build, code generation
and error messages

with corresponding tests like

    if 7 in debug:
        ...

Given that when I'm not debugging the list is empty, these tests are not
unduly time-consuming. But then I've often gone over the top to allow
selective testing in complex developments.

regards
 Steve







More information about the Python-list mailing list