chromatic chromatic-at-wgz.org |Perl 6| wrote:
It shouldn't be.
So you are saying that in the example of
class C {
has $.a;
method a ($self:)
{
side_effect();
return $self.a;
}
} # end C
class D is C {
method foo ($self:)
{
# ...
$x = $self.a;
# ...
}
} # end D
that the variable-notation access in foo will call the explicit accessor
method C::a? I suppose the use of $self.a in method a would be an
infinite loop, and must be $self!a to work.
In that case, why allow the variable-name form at all?
Why keep the variable syntax?
Uniform access principle. See also "Why Java programmers fetishize their
IDEs, reason #482: autogeneration of metric boat-loads of accessors/mutators
at just the click of a button."
That seems to be saying that using the method-call form is preferred, as
it abstracts whether it is a real hard attribute or not. Since my
question was why keep the variable-name form, I think we are not
understanding each other.
I'm getting a picture of 3 forms of access: Really direct, direct but
asking the class to access it rather than knowing how storage works, and
indirect that may involve your own code to do other things besides just
get/set the attribute. But I think the middle one can be handled
invisibly by the compiler -- it's no different from a tied hash.
That really depends on how much external syntax you want to change if you
change the internal representation of an object. For me, that's
approximately none.
I don't understand that sentence at all. Again, "invisibly by the
compiler" sounds like what you want.