After I wrote my post I realized I didn't provide enough context of
what I'm doing, hence it is not quite clear to any readers why the heck
I would want this.  The gist is this.  I have a number of algorithms
that perform the same task. I'm trying to assess which ones work better
under which circumstances, which means I'm timing them (interested in
*relative* speed, so Python is acceptable).  I also have a second app
which allows me to "observe" the operation of said algorithms by
consuming such emitted debug objects and graphically displaying the
information therein.  I'm "observing" with a very fine granularity,
which means a debug object is emitted between almost every single line.
Naturally, if every second line is debug code (or worse, as above, 1
line of real code, 2 lines of debug code), the readability of the
algorithm is horrendous, making further development a pain.  Since,
when I'm NOT observing the algorithms then I'm timing them, I want the
debug/observe code to have minimal impact on the runtimes;
instantiating some of these debug objects is rather costly.

There, hopefully this gives a better picture of my motivation.  If
anyone can suggest alternate way to structure such code, I'm all ears
(... well, eyes, really... :)

Your proposal for one-lining the code as "if debug: emit_....."
occurred to me, but for readability reasons I want as visually *short*
a line as possible, so it doesn't detract from the other code. The C
preprocessor was particularly helpful in such "shortening". (e.g.,
print "foo"; DBG(DbgObj(..)); print "bar";)

Hmm, with this setup you can't get any shorter than the instantiation
of the DebugObject... which gives me an idea... the "if debug:" could
be placed within DebugObjectBase, and all the DebugObjects inherit from
it... no... wait... no good, the problem is the following case:
   ...
   # real line of code
   DbgObjFoo(a,b,costly_function(c))
   # real line of code

On a debugging/observing run, the debugging objects occasionally have
their constructor values computed externally, as above, and the
proposed solution would not save us from that costly computation.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to