Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

This is an important point on idiom, and since idiom is a matter of choice of expression, I won't weigh one way or the other, but will caution that Perl's ruthless lack of discipline, while a benefit in many cases, complicates things for those who prefer or need consistent design.

In Perl, there's no difference between a "message" to an object and a "functor" answered by an object. Thus, obfuscation aside, they both have to use the same invocation syntax: $a->b().

The following distinction is my own OO philosophy, sometimes consistent and sometimes inconsistent with others I've seen, but I think it's a very useful paradigm.

Messages should be invoked for side-effects, and should have no immediate return value, so that (1) they can be transaction-wrapped, (2) they never block the invoker, and (3) on some application architectures they can be posted onto a queue instead of handled immediately. If you stick to the "messages have no immediate return value" philosophy, then supporting it with a Perl return $self idiom makes sense.

Functors should not have side-effects (other than local caching), and should have an immediate return value. Again, these benefits complement message handlers: (1) they can be seen as atomic, (2) thus they may need to block, and (3) in a remote architecture, a dumb stub can return cached values but can't actually decide anything behaviorwise.

(Some people may think "ack! invoke for side effects which may not be done immediately?" If you must wait for a message transaction to be realized or verified, you wait with a functor that can block appropriately. Otherwise, you trust it will get done.)

Unfortunately, you can't easily tell a Perl "functor" from a Perl "message handler." They're both just subs. They're both invoked with $a->b(). If nobody makes a mistake, messages can chain with $self, but yet functors can't. Tread carefully.

[ e d @ h a l l e y . c c ]

In reply to Re: Re: chaining method calls by halley
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
    [choroba]: Good morning!

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (7)
    As of 2018-06-21 07:39 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (117 votes). Check out past polls.