in reply to [OT?] Today's Debugging Story

Instead of commenting out code (you might forget to uncomment it), how about using a debugging constant?

BEGIN { require constant; constant->import( DEBUGGING => $ENV{DEBUGGING} ); } hide_console() unless (DEBUGGING);

Replies are listed 'Best First'.
Re: Re: [OT?] Today's Debugging Story
by vek (Prior) on Nov 22, 2002 at 04:07 UTC
    Cheers chromatic, nice idea.

    Update: I should probably point out that I usually set an environment variable for debugging so that I can do this in my programs:
    my $debug = $ENV{DEBUG} || 0;
    The purpose of my post was a more light-hearted reflection of my day (i.e a joke) rather than a serious debugging tip (hence the OT warning in the subject). Thanks for the TIMTOWTDI debugging suggestion though.

    -- vek --
      Using a constant is better if you don't need to switch the value at runtime:
      $ perl -MO=Deparse,-x7 -le'use constant DEBUG => 0; print "test" if DE +BUG' sub DEBUG () { package constant; $scalar; } '???'; -e syntax OK
      In other words, by using constants all of the debugging code is entirely removed from "production run mode". It's advisable because you avoid both the cost at runtime and (more importantly) can more reliably make sure you don't rely on any debugging code side effects. ("What? I can't initialize variables in an assert()?" :^) )

      Makeshifts last the longest.

Re^2: [OT?] Today's Debugging Story
by Aristotle (Chancellor) on Nov 27, 2002 at 11:32 UTC
    You can use constant DEBUG => $ENV{DEBUG}; actually.

    Makeshifts last the longest.