At 11:56 AM 5/3/00 -0700, Jeffrey W. Baker wrote:
>On 3 May 2000, Chip Turner wrote:
>
> > "Jeffrey W. Baker" <[EMAIL PROTECTED]> writes:
> >
> > > Apache::print() dereferences its arguments.  For example, this code:
> > >
> > > my $foo = "bar";
> > > $r->print(\$foo);
> > >
> > > prints "bar" instead of the expected SCALAR(0xDEADBEEF).  Can anyone
> > > explain the purpose of this behavior, or is it a misfeature?  In my case,
> > > this is not the desired behavior.
> >
> > If I recall correctly, this is a performance issue.  If you have a
> > large string you want to print, sending a reference will result in
> > less data copying etc.  I don't know how much it pays off, but it is
> > an intended effect.
> >
> > You could try something like:
> >
> > $r->print("@{[\$foo]}");
>
>Or I could just do $r->print(scalar(\$foo));, but that's not my point.  My
>point is Ewwwwwwwwwwwwwwwwwww.  I just don't like the overloaded
>interface.  Does $r->print() take scalars, or references?  If it takes
>scalars, it shouldn't be dereferencing them.  If there is a performance
>need for passing references around instead of copying strings, that should
>be a different method, perhaps print_ref().  It just seems more clean to
>me.  Is my mindset too C?
I prefer overloading that is documented. It makes things a lot easier to 
remember one method name.

Otherwise, you have to be an expert who remembers common idioms like _ref 
for references... otherwise, people would argue should it be called 
ref_print, reference_print, print_ref, print_as_ref... Programmers have all 
sorts of weird ways to name functions (if you've delved into other people's 
source code) which I hate.

HOWEVER, I think a good argument for NOT overloading print() in this 
particular case is that it is taking over CORE::print. This is contrary to 
documented Perl behavior and is not backwards compatible then right? If 
this is the case, then that seems suboptimal.

Also, I guess I could see the point that since print() is so well defined 
in the core Perl, that people might expect Apache's print to operate 
identically even if it is called directly. And therefore, the behavior 
should not change from CORE::print anyway.

So in summary, I think I am saying that I vote to support your desire 
reluctantly because I am generally a fan of overloading (but not in this 
case if I am interpreting the facts correctly).

Of course, it may be too late because there may be a load of code that is 
dependent on this "Performance improvment". So it may be a moot point anyway.

Later,
    Gunther

__________________________________________________
Gunther Birznieks ([EMAIL PROTECTED])
Extropia - The Web Technology Company
http://www.extropia.com/

Reply via email to