Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I like it. It feels very Smalltalky. You're sending a bunch of messages to the object, so why repeat the invocant? Expressions have results, so why not use them?

In Smalltalk this is called a "cascade", and there's special syntax to support it. In Smalltalk, if you send two messages to the object anObject (i.e., if you invoke two of anObjects's methods), you can use cascading to rewrite

anObject foo. anObject bar.
anObject foo; bar.
Both messages get sent to anObject, regardless of what the first method returns. That is, the return value from foo is ignored. The value of this expression is whatever is returned from bar.

Perl has no notion of method call cascading, so to simulate cascading, all member functions in a simulated cascade chain (except that final one) need to return self. This works great if you're making a chain of calls for side-effects, and less great if you're composing an expression from a set of cascaded calls, and are interested in the final value, because of the requirement that all cascadable methods return self.

My opinion is that cascading is an idiom that doesn't translate well into Perl. Without a special syntax to designate a cascade, a simulated cascade is indistinguishable from a gross violation of the Law of Demeter.

In reply to Re: Re: chaining method calls by dws
in thread chaining method calls by perrin

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (4)
    As of 2018-02-25 00:54 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (312 votes). Check out past polls.