HaloO,

Carl Mäsak wrote:
I really like all the replies I got to this; thank you Moritz,
Jonathan, TSa, Larry, John and Damian.

It was a pleasure to be useful.

From the feedback I received, I will now do the following:

1. Remove "is rw" from all attributes that aren't supposed to be
writable from outside the class.

2. Start using $!foo consistently in methods, for both read and write accesses.

From a best practice POV consider

   class A
   {
       has $.foo = "A";
       has $!bar = "A";

       method blahh()
       {
          say $.foo ~ $!foo ~ $!bar;
       }
   }
   class B is A
   {
       has $.foo = "B";
       has $!bar = "B";
   }

   my $a = A.new;
   my $b = B.new;

   say $a.blahh; # prints AAA
   say $b.blahh; # prints BAA, right?

Shouldn't there be a warning in B that $!B::bar overwrites $!A::bar
without an accessor? And of course the example shows that $!foo in
blahh is not derivation friendly. Or am I getting things wrong and
there can be only one $!foo and $!bar in the namespace of the objects
created from A and B? That is the declarations in B are superfluous
if not outright wrong? Well, or they only affect the generated
constructor and the storage location is shared? The latter would
nicely contrast them to non twigil attributes in the form 'has $foo'.


Regards, TSa.
--

"The unavoidable price of reliability is simplicity" -- C.A.R. Hoare
"Simplicity does not precede complexity, but follows it." -- A.J. Perlis
1 + 2 + 3 + 4 + ... = -1/12  -- Srinivasa Ramanujan

Reply via email to