On 2/14/21 6:02 AM, Marcel Timmerman wrote:
Hi Todd,

I would like to spend one line or two on your OOP keeper. One important aspect of object oriented programming is dat you encapsulate your knowledge into an object. That is, structures and other variables should be kept invisible to the user of your object. That way, you are able to change your algorithms in your object without hurting people in the future.

This is what I see all the time in your keeper;

has SomeType $.some-variable;

On purpose.  I am demonstrating how to use the thing


The variable is, as you know, readable from outside your object,

On purpose.  What good is a variable that can't be used?

but it also creates a dependency on that variable by the users of your class.

Not sure what you are getting at. If you declare "ro" (the default), you get to write to it once during the declaration.
If you declare it "rw", it is open season.  It is up to the
programmer how he wants to use it.

Once used, you cannot change it without causing pain somewhere else.

Not seeing your point.  I program in Top Down.  If I change
a data structure (generic term, not a C structure), I expect to have to alter away. And since everything is broken down into smaller contracts (subs), I usually only have to alter the those few subs that manipulates the structure.

But if you are programming in "stream of conscious", I can
see your point. But that style of programming is almost unmanageable after it is written (write only) anyway
and would be the least of your problems. But it is
fast to program.  Good luck maintaining it.

So what you must do normally;

has SomeType $!some-variable;

The only difference between

   $!some-variable and
   $.some-variable

is the way the magic under the Raku hood handles
the value.

$! reads the value directly from the structure and

$. calls a method Raku creates to read the structure
that if hidden from the user.

So which to use is left up to the programmer as to how he
wants Raku to read it.  $! only real benefit is that
it is faster.  Though I might point out in a super
high level language like Raku, you are looking speed
and ease of development, for which Raku is elegant.
For raw speed, you need to program in C.  Or even
faster, assembly.

In my research, I found many article that made $. and $!
so complicated that my head spun.  So I was explaining
it without all the posturing and obfuscation.  At
times I was wondering if they were not following the "dazzling them with your brilliance or baffle them
with your bull scat" paradigm.

and the other sparingly, like you've shown using native structures!

Now that I am at it, don't use 'self.some-variable' from within your object. It is faster and also better to read to just write '$!some-variable' whether it is made readable or even writable.

I was demonstrating various way of doing it.  Covering
all the bases.  And I did make comment about the
speed issue.


Marcel

Thank you for the feedback!

-T

Reply via email to