SPUG: Debugging methodology (was: How to deal with same name packages?)

Richard Anderson richard at richard-anderson.org
Tue Jan 15 00:08:53 CST 2002


I use both the debugger and optional print statements controlled by a
multi-level debug flag.  My feeling is that if you go to the trouble of
inserting debugging print statements, leave them in but make them run-time
optional.  Someone (most likely yourself) may want to turn them on again in
the future.  Whoever does maintenance on the code will probably thank you.
(Don't forget to document how to use your debug flag.)

Callers of my modules can activate debug messages using a class variable
Debug:

use MyClass;
$MyClass::Debug = 1;         # or 2 or 3
$MyClass::DoSomething();

and in MyClass:

if (Debug > 0) {
   print (whatever)
}

I usually have two or three debug levels of varying verbosity.  The debug
messages are written to standard out or the Apache error log for mod_perl
apps.   The performance impact of checking $Debug is trivial compared to the
benefits.

Richard Anderson
206.547.6903
richard at richard-anderson.org
www.richard-anderson.org
----- Original Message -----
From: "Colin Meyer" <cmeyer at helvella.org>
To: "Andrew Sweger" <andrew at sweger.net>
Cc: "Chris Sutton" <chris at chriskate.net>; "Seattle Perl User's Group"
<spug-list at pm.org>
Sent: Monday, January 14, 2002 6:54 PM
Subject: Re: SPUG: How to deal with same name packages?


> On Mon, Jan 14, 2002 at 06:20:53PM -0800, Andrew Sweger wrote:
> > mod_perl? Beyond me. That sounds like a tough one. But I *know* there's
at
> > least one very busy individual that should know the answer to this.
> > Skimming perl.apache.org didn't give any obvious answers, but I'm sure
> > there are hints there.
>
> http://perl.apache.org/guide/debug.html#Interactive_mod_perl_Debugging
>
> ;-)
>
> > >
> > > Help, I really want to stop using print STDERR!  Can I make database
> > > connections in the debugger?
>
> Very certainly.
>
> > >
> > > On Monday 14 January 2002 03:46 pm, Andrew Sweger wrote:
> > > > To all of you _still_ using debugging print statements, I urge you
to give
> > > > the Perl debugger a try. I will never go back to print statements.
If you
> > > > tried the Perl debugger and went back to print statements, speak up.
I'd
> > > > be curious to know what problems folks ran into (reasons other than
not
> > > > actually learning how to use the debugger). I already realize that
> > > > learning the Perl debugger is hard work. It is worth it!
>
> I tend to rely on a combination of print statements, logfiles and perl -d.
>
> For edit, run, edit style coding (short scripts), the following is so
> convenient that I'll never give it up:
>
>   print STDERR "value: $value\n" if $DEBUG;
>   # actually I typically code a sub and just:
>   # debug("value: $value");
>
> For large projects, I use a central logfile for tracing data as it is
> aquired, filtered, convolved and passed along between bits of the
> system. Entities logging to the file identify the date, themselves, the
> data, and what they are up to. This makes it easy to pick out which
> section in 10k lines of code that is doubling lines of output. (anybody
> use a cpan module for syslog style application logging?)
>
> Both of these need the help of perl -d to unwind hairy problems.  The
> ease examining data and being able to tweak things, single step through
> code, set conditional breakpoints, etc is simply the best for digging
> deep.
>
> Have fun,
> -C.
>
>
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>      POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
>       Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
>   Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
>  For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
>      Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/
>
>
>


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/





More information about the spug-list mailing list