Aaron Sherman writes:
: On Thu, 2002-04-11 at 00:42, Luke Palmer wrote:
: > > Ah, but I think the mnemonic value of the '.' more than earns its keep
: > > here. C<our $foo is private> is doing a slightly different job
: > > anyway. And instance variables are *not* the same as 'normal'
: > > variables, they hang off a different symbol table (or syte, to use
: > > Damian's oh so clever term from Perl 5+i) and I'm all for things that
: > > are different *looking* different.
: > >
: >
: > Well, I certainly don't like the aesthetic value of them. They are ugly
: > as Perl 4. But, I have been caught in C++ making all my private variables
: > _named _like _this, so I suppose it's analogous. But I don't like being
: > forced to do it that way.
: >
: > What if you just want a simple struct-like thing? That's when it becomes
: > really ugly and dislikable. Erm... wait a minute, how would you do that?
: >
: > $foo = new Foo;
: > $foo..instancevar = 7;
: > I doubt that's it.
: >
: > $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.
Larry