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

Tim Maher tim at consultix-inc.com
Mon Jan 28 16:37:16 CST 2002


On Sat, Jan 26, 2002 at 09:53:32AM -0500, Michael R. Wolf wrote:
> "Richard Anderson" <richard at richard-anderson.org> writes:
> 
> > $MyClass::Debug = 1;         # or 2 or 3
<SNIP> 
> > if (Debug > 0) {

You meant:
> > if ($Debug > 0) {

> >    print (whatever)
> > }
> 
> I, too, use statements like this, but format them as follows:
> 
>     print STDERR "Debug/Assertion statement" if $debug;
>  or
>     print STDERR "Debug/Assertion statement" if $debug > 1;
> 
> The reason I like this is that it reads as an assertion
> comment for casual human readers, but runs like an if
> statement.
> -- Michael R. Wolf

Personally, I rarely use this syntax, despite its purported "ergonomic"
advantages, because in doing so I risk having to restructure the whole
statement later on when I find a need to do a *second thing* conditionally:

>     print STDERR "Debug/Assertion statement" if $debug > 1;

BECOMES:
     if ($debug > 1) { print STDERR "Debug statement" ; second_thing; } 
OR even:
     do { print STDERR "Debug statement" ; second_thing; } if $debug > 1;

Using an if-construct in the first place guarantees that this part of
the program can evolve without being restructured.  Sure there's a speed
tradeoff, because of the overhead of setting up the new scope for the {
}, but that's one I'm often willing to accept.

But, of course, TMTOWTDI! 8-}
 
*===========================================================================*
| Dr. Tim Maher, CEO, Consultix          (206) 781-UNIX/8649;  ask for FAX# |
| EMAIL: tim at consultix-inc.com           WEB: http://www.consultix-inc.com  |
| TIM MAHER: UNIX/Perl  DAMIAN CONWAY: Adv. Perl  COLIN MEYER: Perl CGI/DBI |
| CLASSES!  FEB: Unix; Perl; APR: Shell; Int & OO Perl; Perl Database w/DBI |
*===========================================================================*

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     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