Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^2: Roles and functional programming

by dragonchild (Archbishop)
on Dec 01, 2008 at 20:43 UTC ( #727212=note: print w/replies, xml ) Need Help??

in reply to Re: Roles and functional programming
in thread Roles and functional programming

Roles don't -have- attributes. Roles can -provide- attributes to the classes they are composed into. If you have a Cat and Dog, each of which does Pet, then if you have a $cat instance and a $dog instance, the $.collar attribute of each is separate. They aren't shared in any sense. Therefore, Perl6 roles -are- stateless in that the role itself doesn't have any state. (Which makes sense given that you cannot instantiate a role.)

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re^3: Roles and functional programming
by BrowserUk (Pope) on Dec 01, 2008 at 22:54 UTC
    Roles don't -have- attributes.

    Hm. The quote was directly from Synopsis 12, so as far as the wording is concerned, you need to argue with the authors.

    As far as the semantics are concerned, I did go on to say: "Of course, whatever state they have becomes a part of the instance into which they are composed", so I think we're in tune there.

    But, as I also said, and regardless of whether the state is has'd by the Role, or provided by it, that state exists and is presumably usually affected by the Role and persists beyond the invocation of whatever methods the role also provides, so there is no sense in which it can reasonably be described as stateless.

    If my limited understanding of ML's Functors means that they are like (my also limited understanding of) Haskell's Typeclasses, then the term composed in the sense you are using it: "composed into"; and that same term in the sense the OP used it: "more easily composable units."; are entirely different things.

    With the former composing both operations and state, and the latter performing operations on values only (hence stateless). Quite different beasts. The best discussion I have located upon the difference is this.

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Yeah, that wording is somewhat poor. It really should say something like "Roles can provide attributes." Except, of course, the Role actually has the attribute if you consider the class as a composition of separate roles with the class itself being an anonymous role that is instantiable (which, if you think about it, is one of the two major differences between a class and a role (the other being that a class has to be complete and a role can be incomplete)). And, in any case, the instance of the class is the thing that actually has the attribute, the class merely being the template by which instances are created.

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://727212]
[Lady_Aleena]: Corion, so do you think the gods would be open to taking over Cookies should I disappear for too long a time?
[Corion]: Lady_Aleena: Yes, I think so, but maybe someone else might also take care of the cookies ;)
[Lady_Aleena]: I'll put it out there.

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2017-04-26 08:34 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (471 votes). Check out past polls.