Using debug print routine inside assert

Edvard Majakari edvard+news at majakari.net
Tue Nov 4 08:59:20 EST 2003


Ben Finney <bignose-hates-spam at and-benfinney-does-too.id.au> writes:

> The debug routine looks elegant and useful; thanks.

You're welcome :)

> The instance of its use is the problem.
>
> You're performing two discrete operations: get the result of the
> subfrobnicate() call, and then emit a debug message.  The problem isn't
> with the debug message -- it's with the subfrobnicate() call.  Or more
> precisely, the fact that you only seem to be using it for the debug()
> call.
>
> If the code only ever uses subfrobnicate() when you emit the debug
> message -- which isn't going to occur in the released program -- you
> don't really need to see it.

I think I got your point. In general you are right, but consider the
situation: you have a complex data structure (graph linked to
some complex, associated data) and you use it in your program. Suppose
subfrobnicate() doesn't return any values usable by program, but instead
it traverses the data structure and converts the representation from
(eg) numerical to more human readable form. Then the only use for
subfrobnicate() would be inside a debug-like print statement, and my
original question is valid.

Then again, if somebody suggests that proper architectural design of the
software helps to avoid that kind of problems, I'd say he's right but I'd
also welcome him to real life, where debugging is always part of the
software process.

> If the result of subfrobnicate() is important enough that you want to
> track it with a debug() call, it's probably because you're using the
> same result elsewhere.  So why are you calling it each time it's needed?
> Calculate it, emit the message, then use it some more.

> Either the subfrobnicate() call is a waste of cycles -- remove it.  Or,
> it's a necessary part of the program -- keep its result for use in the
> debug message *and* the main program.

See above. Would this be a place for PEP ?-)

-- 
# Edvard Majakari		Software Engineer
# PGP PUBLIC KEY available    	Soli Deo Gloria!
One day, when he was naughty, Mr Bunnsy looked over the hedge into Farmer
Fred's field and it was full of fresh green lettuces. Mr Bunnsy, however, was 
not full of lettuces. This did not seem fair.  --Mr Bunnsy has an adventure 




More information about the Python-list mailing list