On Thu, Sep 8, 2016 at 12:25 AM, Kaare Rasmussen <ka...@jasonic.dk> wrote:

> I wonder what you miss from https://docs.perl6.org/language/classtut. To
> me, it explains the hows and whys very thoroughly. Now, I now people have
> been hard at work improving the documentation, so if you can point to
> what's missing or unclear, I'm sure it will help a lot.


I forgot I looked at this before. The Task example doesn't really help a
newcomer because it is combining too many new things at once:

* BUILD
* submethod
* new
* bless
* named arguments syntax
* slurping parameter syntax
* code golfing cleverness of mapping arguments to identically named named
arguments

The real nail in the coffin though is that it's an example that doesn't
need to use any of those features (nothing about Task really require
special construction), so a quick read just makes it look like it's a very
verbose syntax for doing something you normally get for free, rather than
showing how it allows you to do things that you otherwise wouldn't be able
to do.

The rust developers talk about having a "strangeness budget", because if
you introduce too many strange things at once people give up. Every
object-oriented language I've used has one constructor-like method that you
define. That Perl6 has two is really strange and unusual (at least coming
from the background of somebody who has "only" been exposed to
C++/Java/Python/Lisp/Haskell). Strange and unusual enough that it seems
like there should be an example that specifically focuses on what you get
out of having two, and when you should be using one versus the other. And
frankly I'm not sure if it's actually two, because bless is also apparently
a method (that may be you can override as well?!), even though it is
supposed to be what you call to construct the object that hasn't yet been
constructed... see why this might be confusing? It would be especially
great if it contrasted with another language where you could demonstrate
that it's awkward to do something without the feature.

Here are some fairly simple things that I was left wondering how to do:

* If I have a member that is read-only, when am I allowed to initialize it
and after what point must already be initialized? Can I assign to it in
BUILD but not new or vice versa?

* If I want a constructor that takes positional arguments, do I write new
or BUILD?

* If I need to do some computation when the object is constructed in order
to properly initialize the members, do I write new or BUILD? What if one of
the members I need to initialize is read-only?

* Can either new or BUILD be a multimethod? Overloading constructors is
fairly common in C++ at least.

>> The pair operator is explained here https://docs.perl6.org/languag
e/operators#index-entry-pair_constructor and word quoting here
https://docs.perl6.org/language/quoting#Word_quoting:_qw - perhaps they're
more Perl 5-like, but both are very handy features. Perhaps you can expand
a little as to what you'd like explained. Coming from Perl 5, I'm certainly
damaged in that respect.

Functions (including operators since they are just functions with a
different calling syntax after all) normally just operate on their
arguments without knowing anything about the context with the function was
called. But the pair constructor operator **reaches back magically into the
place where it was called and changes the argument it was given into a
string** (because otherwise it would be an undeclared variable name).
That's the kind of thing that in most languages you either can't do or you
can only do by defining a macro. I've never seen anything like it. And
going with the strangeness theme none of the tutorials seemed to be the
least bit fazed by it, while I think somebody coming from a background
without Perl will be bewildered by it.

Reply via email to