No, my code just provided the data for the Effect object to do its job. Your code put actual code (subroutine refs) to do the job. I want all of this information hidden away by the object.
Hidden from who? There's no point in hiding it from the caller as the caller is the one that specified what should be done. There's no point hiding it from the object as it needs to know what it's being asked to do.
The example replacement ([ salary => 1.02, '*' ] with $effect->salary *= 1.02), is a matter of syntax. It's not a fundamentally different design.
One fundamental difference is that as it stands, yours doesn't appear to handle complex expressions and if you were to extend it so it does you'll probably end up with lisp (because lisp is basically written as a parsed syntax tree) but without all the other great stuff that lisp gives you.

A quick google search for encapsulation brings up various conflicting definitions including some pages that say that it's not about information hiding at all. As far as I'm converned a trivial mutator exposes nothing. The justification for this is that the thing using the object doesn't know whether it's a trivial mutator or not, all it know is that here's this thing which seems to behave like a storage location for data.

What do you mean by exposed? I mean that some part of the object can be twiddled outside the control of the object itself. This deifinitely is a bad idea but it's not what's happening in a trivial mutator because the object is still in control.

Do you take X is exposed to mean that X can is influenced by or visible to outside things but remains under the control of the opject? If you do then pretty much everything in the object is exposed in some way (anything in the object which is not at all influenced or visible by other parts of the system would seem to be irrelevant).

You seem to be arguing that an object which has one or more things that seem to behave as storage locations for data as part of it's public interface is fundamentally broken. So you're disallowing the concept of a variable as part of an objects interface. I still haven't seen an example of the bad tings that happen when objects have variables in their public interfaces.

Forgetting about the salary example (because it allows for setting a new value relative to the old value), what about a person with a hand. Why not allow

$person->HandItem = $thing; print 'he's holding a ".$person->HandItem->name."\n";
a variable is a perfectly natural interface for this. Any other flexible interface will effectively be an accessor and a mutator just with different names.

In reply to Re^20: Assignable Subroutines by fergal
in thread Assignable Subroutines by dragonchild

Title:
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, details, 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, summary, 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.