Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Re: IYHO, what do you consider good code?

by Anonymous Monk
on Jun 13, 2003 at 16:43 UTC ( #265731=note: print w/ replies, xml ) Need Help??


in reply to Re: IYHO, what do you consider good code?
in thread IYHO, what do you consider good code?

Usually when writing debug code, I will use this type of statement (for just the reason above)...

use constant DEBUG => 1; ... ... warn "Foo" if DEBUG;
or
use constant DEBUG => 1; ... ... my $debugsub = DEBUG ? { warn @_ } : {}; #need to fix stack trace... ... ... &$debugsub(foobar);
Allows turning it off in one location. Just my $0.02.


Comment on Re: Re: IYHO, what do you consider good code?
Select or Download Code
Replies are listed 'Best First'.
Re: Re: Re: IYHO, what do you consider good code?
by chromatic (Archbishop) on Jun 13, 2003 at 23:51 UTC

    Make it an environment variable and it's even easier:

    BEGIN { $ENV{DEBUG} = $ENV{DEBUG} ? 0 : 1; } use constant DEBUG => $ENV{DEBUG};

    Update: Good points both responses, though I'm slightly happier with the BEGIN block from a maintenance standpoint.

      Make it a more specific environment variable and you're golden. Alzabo respects the ALZABO_DEBUG environment variable, your modules could do something similar.

      BEGIN { $ENV{DEBUG} = $ENV{DEBUG} ? 0 : 1; } use constant DEBUG => $ENV{DEBUG};

      Why the BEGIN block?

      use constant DEBUG => !!$ENV{DEBUG};

      Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://265731]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2015-07-30 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (270 votes), past polls