[Wellington-pm] A question about scopes

Cliff Pratt enkidu at cliffp.com
Tue Mar 28 02:35:52 PST 2006

Jacinta Richardson wrote:
>> sub calc_move { # Calculate next move my $self = shift ; my $i ; 
>> for ($i = 0; $i < 81 ; $i++) { # check_element($i) ;
> $self->_check_element($i);
>> } }
Ah, I see! I 'solved' it by calling check_element with an extra parameter:

	check_element($self, $i) ;

Your way is much more elegant! I 'faked' the method call as I was
thinking of it as a sub....
>> sub _check_element {
> my $self = shift;
>> my $element = shift ; . . }
> Of course, if _check_element doesn't *need* to know anything about
> the object, (that is, it's not a method) then it's just a regular
> subroutine and you'd call and define it as such (which is what you
> had done).
> private methods rely on programmers behaving because it's polite, not
> because you force them to do so.  There's some quote here about a
> shot-gun, but I can't remember it off the top of my head.  This would
> apply too to private subs. After all, the programmer usually has
> access to your source code when they "use" your module, so they can
> break any strictures you set up anyway.
True. Even with a compiled program it can be decompiled. Politeness is
fine, but to some extent you might want to hide some of the workings of
your object. An object is *supposed* to be opaque, isn't it.





More information about the Wellington-pm mailing list