On Thu, Apr 11, 2002 at 08:49:40AM -0700, Larry Wall wrote:
> Aaron Sherman writes:
> : On Thu, 2002-04-11 at 00:42, Luke Palmer wrote:
> : > $foo.instancevar = 7;
> : 
> : This should not be allowed.
> 
> Well, that depends on what you mean by "this".  :-)
> 
> That is, in fact, calling an accessor function, and if it's not allowed,
> it's because the attribute is marked private, not because we're against
> people thinking of it as a struct.
> 
> : External code should not access instance
> : variables. We did discuss the idea that accessors would be created
> : automatically, and coincidentally, you're using the correct syntax for
> : that above, but certainly there should be the ability to override the
> : default accessor and to declare an instance variable as accessor-less.
> 
> By default attributes are private, which means the corresponding
> accessor name is also private.  There's no need to override the
> automatic accessor merely to make something accessor-less to the
> general public.
> 
> : In Perl5 C<$object{instancevar} = 7> is just frowned on. In Perl6, I
> : thought we had agreed that it would flat out be impossible.
> 
> Who agreed to that?  First of all, it's perfectly possible that (for a
> non-hash) that syntax is isomorphic to
> 
>     $object.instancevar = 7;
> 
> since I've already said that any object can be used as if it were a
> hash.  Plus we'll have lvalue methods in some fashion or other.  Not by
> default, of course.  It's up to the class to decide how much it wants
> to break encapsulation.

One of the features I like about Eiffel is what Meyer calls the Uniform
Access principle, which he describes as "All services offered by a module
should be available through a uniform notation, which does not betray
whether they are implemented through storage or through computation."

In other words, the users of my module shouldn't have to worry about
whether they are calling a method or accessing an instance variable, and
when I change my implementation from one to the other they shouldn't
have to change their code.

See http://www.elj.com/elj/v1/n1/bm/urp/ for more details.

Languages like C++ don't support this and you end up writing lots of
accessor functions.  Do that in Perl 5 and you pay the price of calling
a subroutine.

It sounds as though Perl 6 is heading towards supporting this.  Have we
actually got there?

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

Reply via email to