Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: IYHO, what do you consider good code?

by one4k4 (Hermit)
on Jun 13, 2003 at 15:46 UTC ( #265714=note: print w/replies, xml ) Need Help??

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

Turn off debug statements. I don't know how many times I've had to read through apache error_log files and determine what/where/why/when some piece of code written by somebody here is writing to stderr..

I find it useful to do things like warn $sth when developing, but forgetting to remove those bits leads to production log file messes.

:) Just my $0.02

One4k4 - (

Replies are listed 'Best First'.
Re: Re: IYHO, what do you consider good code?
by Anonymous Monk on Jun 13, 2003 at 16:43 UTC
    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;
    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.

      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 => '', plp_site => '', do_not_use => 'spamtrap' }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://265714]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2018-07-18 22:34 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (397 votes). Check out past polls.