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

Re: Mutator chaining considered harmful

by Anonymous Monk
on Dec 30, 2004 at 02:10 UTC ( [id://418157]=note: print w/replies, xml ) Need Help??


in reply to Mutator chaining considered harmful

I wrote about this in my use.perl journal at http://use.perl.org/~Revelation/journal/12867.

Looking back, I had to major problems (that weren't all that well articulated):
  • Chained method calls make backwards compatibility hard to do, if you make an attribute into its own object at any time. You can't use Want.pm, because either way you want an object.
  • Chained method calls force a person reading to check whether a mutator has returned the same object or a more specific object.

    I agree with you. Not a big fan.
  • Replies are listed 'Best First'.
    Re^2: Mutator chaining considered harmful
    by Anonymous Monk on Dec 30, 2004 at 09:35 UTC

      Chained method calls make backwards compatibility hard to do, if you make an attribute into its own object at any time. You can't use Want.pm, because either way you want an object. You mean, it makes it difficult to change a method such that has a different return value? Well, that always is non-backwards compatible. Whether the user chains, or stores the result in a variable and does something with the variable, it's going to be non-backwards compatible.

      Chained method calls force a person reading to check whether a mutator has returned the same object or a more specific object. And that's different from storing the result of a method (whether said method is a mutator or something else) in a variable, and call a method in said variable?

        Re: And that's different from storing the result of a method (whether said method is a mutator or something else) in a variable, and call a method in said variable?

        Yes, it is. Consider:  $people->bob->eye('green')->color;. As a reader, I assume that the call is returning an 'eye' object, not bob, again. But if eye's a mutator, then you might find out Bob's a brown man.

        Re: You mean, it makes it difficult to change a method such that has a different return value? Well, that always is non-backwards compatible. Whether the user chains, or stores the result in a variable and does something with the variable, it's going to be non-backwards compatible. In most cases you can make it backwards compatible through Want.pm. But perhaps, this is an issue of my style...?

    Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Node Status?
    node history
    Node Type: note [id://418157]
    help
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others examining the Monastery: (7)
    As of 2024-03-28 11:14 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found