Fwd: Re: SPUG: Last night's meeting

Marc M. Adkins Perl at Doorways.org
Thu Mar 18 16:10:56 CST 2004

>> Condemn all debug print statements now!
> IMHO, the humble print statement has a significant advantage over
> any interactive-debugging based strategy, which is simply that it
> will still be there if/when the program breaks again, and it can
> easily be re-activated to deliver its benefits again.
> AFAIK, there's no way to preserve the activities of an
> interactive debugging session, and replay them at a future time.

I have a (Filter::Util::Call) filter that I've been using for a number of
years to turn trace statements embedded in comments on and off.  I can turn
on individual trace statements or blocks of trace statements by keyword or by
subroutine with only a few keystrokes.

	use Trace	qw(KEYWORD);

	#!#	warn "Trace statement off\n";
	#*#	warn "Trace statemetn on\n";
	#!#	warn "Trace statement w/keyword on\n";	#[KEYWORD]
	#!#	warn "Trace statement w/keyword off\n";	#[WRONGWORD]

	sub	function
	  #!#	warn "Trace statement off\n";
	  #$#	warn "All remaining trace statements in routine on\n";
	  #!#	warn "Trace statement on\n";

Since it's a filter, when they're off they're just comments and so there is
_no_ run-time cost.  I can leave them in the code forever.
It's remarkable how few lines of code this is (even w/o Filter::Simple) and
how powerful it is in practice.

And yet...I hesitate sometimes to mention it in 'polite' company because
 there seems to be a subtle prejudice in favor of debuggers of infinite power
 among "real" programmers.  Hummph. [sic]  I get a lot of mileage from the
 humble print statement.


More information about the spug-list mailing list