Quantum Debugging

December 17th, 2003 4:47 PM

I haven’t decided yet whether this is mildly clever or absolute nonsense, but I recently started using a Quantum::Superpositions object as my debug flag. So instead of saying,

$debug = 1;
warn "penguin on fire" if ($debug);

I am instead using,

$debug = any('initialization', 'penguin');
warn "penguin on fire" if ($debug eq 'penguin');

This allows the grouping of debugging information into sets, each of which can be turned on or off independantly. Also, when the code moves into production, there are no dependencies and little overhead if the use statement and the $debug definition are commented out. Of course, I could just as easily say,

%debug = ( penguin => 1 );
warn "penguin on fire" if ($debug{'penguin'});

which would have the benefit of allowing multiple levels of debugging information for each group (cluck "penguin on fire" if ($debug{'penguin'} > 2)).

I have a feeling that I really just like the novelty of using Quantum::Superpositions module in debugging. That doesn’t mean, though, that I won’t continue using it for now.

#Perl
Next: Subtitles
Previous: Bah