Best way to work in debug code?

Quinn Dunkan quinn at drachma.ugcs.caltech.edu
Mon Jan 17 20:04:40 EST 2000


On Mon, 17 Jan 2000 09:19:08 GMT, rdudfield at my-deja.com
<rdudfield at my-deja.com> wrote:
>Hello,
>
>
>Just wondering how you people write debug code in your functions
>/methods?
>
>I personally write a "if (DEBUG_LEVEL >= 5):" around the code.  However
>this reduces readability.

I have a dprint(msg) function that writes msg to stderr if debugging is set,
or to a file if debug_log is set, and occaisionally use assertions.  I've
never found it useful to get more complicated than that.  The only time I've
found it useful is for long-running processes that try to do complicated
stuff.

If you put code in if __DEBUG__: (or assert expr) then python -O will
"optimize" it away.  If you don't want to see debugging stuff in code, perhaps
a folding editor is the way to go (vim will do it eventually).

And then, if your code needs that much debugging, perhaps simplifying,
componentizing, and writing test harnesses is a better solution.



More information about the Python-list mailing list