On 25 May 2001, Chip Turner wrote:

> Stas Bekman <[EMAIL PROTECTED]> writes:
>
> > > You can have the checks in during development, and pull during
> > > production.  It's not 100% efficient, but it's pretty close.  With
> > > some use constant magic, you may even be able to get the compiler to
> > > optimize away the entire line at compile time, resulting not even in a
> > > check on the value of $DEBUG in production environments.
> >
> > which is true only if it's:
> >
> > use constant DEBUG => 1;
> >
> > and not:
> >
> > $DEBUG = 1;
>
> Right; hence my veiled reference to 'use constant' magic :)

oops, sorry, I didn't mean to say you had a bad suggestion. I was just
trying to stress that $DEBUG is bad, since quite a few people will think
that if they use $DEBUG it makes things magical, if they don't really know
about 'constant' pragma (or just simple subroutine).

> > Basically you should be able to turn the development checking at compile
> > time for the whole project via startup.pl:
> >
> > use My::Init qw(PRODUCTION);
> > vs.
> > use My::Init qw(DEVELOPMENT);
>
> I like this method of turning debug on and off.  Hadn't seen this
> novel method, but it has a nice feel to it.

Heh, I "invented" it while responding to your email. And I like it too :)
In fact I should start using it right away.

I think Damian Convey uses this sort of technique in his Class::Contract,
so I cannot claim the patent :)

> > To conclude, if you make all your checkings/validations only in debug
> > version it doesn't matter how fast or slow they are. I think what matters
> > here is the clearness of the code.
>
> I agree 100%.

I even think that in some cases it might be useful to write a whole
Validation module, to have the code as little cluttered as possible with
validation code. Since it'll be stripped away at compile time on
production server, there is no fear to have validation functions as
methods for example.

_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide
mailto:[EMAIL PROTECTED]   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/


Reply via email to