develooper Front page | perl.perl6.language.objects | Postings from August 2000

Re: $ME in a method called as a subroutine

Thread Previous | Thread Next
From:
David L. Nicol
Date:
August 22, 2000 13:09
Subject:
Re: $ME in a method called as a subroutine
Message ID:
39A2DDD6.F781F9CE@kasey.umkc.edu
Markus Peter wrote:
> 
> --On 22.08.2000 18:24 Uhr +0000 David L. Nicol wrote:
> 
> >
> > Regardless of what its called, in a method called as a subroutine,
> > the variable could refer to the last instance of this kind of object
> > used by this thread.
> 
> Hmm.... Does that mean if I once all $obj->method() and then afterwards
> somewhere else obj::method() then $ME or whatever it is called still holds
> $obj ? If yes, why? I can imagine _some_ cases where that's useful,
> especially if someone is sloppily mixing procedural and object oriented
> programming, but I can also imagine many more cases where it adds
> confusion.


Yes, that's pretty much it.  More opportunity to be lazy, but only
if you know how.  This way the authors of methods never have to fiddle
with checking ever again.  And users who call methods like subroutines
had better know what they are doing or they are unwisely meddling in the
affairs of wizards.


> holds specifically the last object (like $LAST_ME or whatever) or one which
> holds information about the way the sub was called. I'd still prefer the
> first alternative then as it appears cleaner to me somehow.


We need a whole pile of them, one for each thread.  I think that is better
than having each thread keep track of a hash of each object.  These are
implementation details.


It would also be another way to get "with"  -- you use an object, then
you can start throwing around access methods.  But you don't have to be
within the block.  

So yes, some discipline would be required, so the people who don't
have pets don't start causing appointments to be scheduled with their
pet-having alphabetic neighbor's veterinarians, perhaps some sort of
global reset function that undefs every $LAST_ME for the thread we're in?

So yes, there is another side to the coin, but i don;t think its too ugly
and I think it would be better than not allowing methods to be called at all
except as methods, which would be what is reccommended in the introductory texts
and is what C<use strict> might require.


CC this to people on strict who don't read objects?  I read -all

-- 
                          David Nicol 816.235.1187 nicold@umkc.edu
                                      laziness with responsibility

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About