On Sun, Sep 10, 2000 at 04:00:30PM -0700, Nathan Wiger wrote:
> > Normally, the Foo::lock() subroutine in the current package will be
> > called. However, if %trans is a tied hash to a class which defines a
> > lock() method (let's call it Lock::Ness) the meaning of the program
> > radically and unexpectedly changes.
> 
> That's true. However, this is actually no different than the situation
> currently with blessed objects. If the code was rewritten:
> 
>    sub lock { print "Hello!" }
>    $trans = new Lock::Ness;   # ;-)
>    lock $trans;   # $trans->lock
> 
> The lock method from the $trans object would be called, even though
> there was a main::lock, because of the higher precedence and binding of
> indirect objects.

That's not right.

    package Lock::Ness;  
    sub lock { print "Nessie\n" }  
    sub new { bless {} }  
    
    package Foo;  
    sub lock { print "Foo lock\n" }  
    my $trans = Lock::Ness->new;  
    lock $trans;

Run it.  The result is "Foo lock".  That's the way it should be, for
the same reasons I've already pointed out.  You don't want adding a
method to a class to suddenly alter the behavior of distant code.


> > But this doesn't really win you much besides some syntactic sugar.
> > Consider this code:
> > 
> >     lock $trans{$var};
> > 
> > What if %trans is not tied?  Then a lock() subroutine would have to be
> > in scope
> 
> However, here in the tie case I think it actually gains you a lot more
> than just sugar. Without this facility, you have to mix OO and tied
> calls
<snip>

No, I'm saying that if you're solely expecting %trans to always be
tied and lock() to always be called as a method (which you have to,
else you'd have to have a lock() method and a lock() function as I
pointed out), then you may as well just have designed your interface
as straight OO in the first place.  Tying just buys you some cute
syntax in this case.


<arguments for the RFC sniped>
> This is the problem that the RFC is attempting to solve. So in this
> case, the indirect object syntax actually buys a lot.

Yes, it does help solve those problems.  The dangling untie() will
happen less frequently, and you can customize the hell out of your
tied class.  But you're trading those problems for a new set of
ambiguities!


PS  Your reply to Fowler hasn't hit the archives yet, so I'll hold off on 
jumping on his points until then.

-- 

Michael G Schwern      http://www.pobox.com/~schwern/      [EMAIL PROTECTED]
Just Another Stupid Consultant                      Perl6 Kwalitee Ashuranse
<GuRuThuG> make a channel called Perl, and infest it with joking and
fun....it doesnt make alot of sense.

Reply via email to