On Thu, Sep 8, 2016 at 4:00 AM, Joseph Garvin <joseph.h.gar...@gmail.com> wrote:
> * I can find no concise easy-to-understand explanation for how to define
> what other languages would call constructors. Instead there is a mess of
> bless, magic inside Mu, new, BUILD, BUILDALL... It's not clear when you
> should prefer to override BUILD or new or both. I also assume there are some
> benefits to teasing apart object construction this way, but right now I
> don't know what they are. This is also an area where I think there are older
> blog posts confusing the situation because they discuss semantics from an
> older version of Perl6.
In perl6 default way is to not write new, BUILD or BUILDALL and also
not to write accessors. When you create object you can provide
attributes to initialize, default accessors are generated if field is
declared with $. sigil. OOp was designed to not write the same code
everytime. When I started using perl6 the doc didn't told me it but
IMHO the best way to learn is read others code.
> I haven't been able to find any guidance on when I should be using a role and
> when I should be using a class. The former seem to give you better error
> messages when you forget to define a method from a base role... So never use
> classes? I suspect it's more complicated than that.
Roles are similar to mixins. You can add something to class without
all complications of multi inheritance. IMHO *is* and *does* keywords
in most cases explain best whether you want class or role. I
generally use classes for data and roles for code because I like to
separate data form implementation. I hurt a lot of times while was
trying to do java programming with perl6 then I realized roles are not
interfaces and code is not compiled in static language sense.