On 25 May 2001, Chip Turner wrote:

> brian moseley <[EMAIL PROTECTED]> writes:
>
> > you can certainly say "the nth parameter implements
> > interface Foo::Bar", and provide Foo/Bar.pod that describes
> > the interface, and get the exact same benefit.
>
> Of course.  But you lose nothing by actually making it an ISA
> relationship; you don't even lose performance.  Plus you could do
> something like this:
>
> sub foo {
>   my $self = shift;
>   my $bar = shift;
>
>   $self->die_because_of_bad_bar_parameter
>     if $DEBUG and not $bar->isa('SomeBase::Class');
>   ...
> }
>
> 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;

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

where the My::Init::import() method will load and compile all the modules
that are going to be used, but only after My::Config::DEBUG constant is
either set to 0 or 1.

So you don't have to remember to manually modify every module, in fact
none of them. startup.pl time resolution will make things really flexible.

On the other hand under mod_cgi this can be done in the first BEGIN block
of every script that you use (but then it's cumbersome, since you have to
modify all the scripts all the time, and possibly conflict with CVS) but
hey, we are on the mod_perl list :)

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.

_____________________________________________________________________
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