Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Comment on

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

I think the entire idea of rvalue accessor methods is flawed, now that we have the possibility to create lvalue ones. Since years ago, I have made programming much easier for myself by inventing some very simple rules:

  • Methods should behave like subs
  • Object variables (properties in Perl 5 jargon, attributes in Perl 6 jargon) should behave like variables
  • Typing curlies sucks, as does exposing ALL internal variables.
Why should they behave like variables? Because in Perl, variables are powerful. They are lvalues, and they can be modified efficiently without copying the values. But mostly because they ARE variables, and as much as I like using black boxes with no knowledge of the internals, I do not wish to hide that these things are variables. Hiding that takes away a lot of power that lies in how Perl's variables work. To have this power without providing an lvalue interface, you'd need to create a method for every operator and function that uses lvalues.

Value validation used to be a good reason not to use lvalues. But there is Attribute::Property now. Not that I use it myself, though: sub foo : lvalue { shift->{foo} } (or sub foo : lvalue { $foo{+shift} } for inside-out objects) has proven to work very well, and value validation is something I don't do much (I expect people to RTFM).

$person->name; # get the name $person->name("Ovid"); # set the name $person->name(do { (my $temp = $person->name) =~ s/Ovid/Juerd/; $temp +}); $person->name($person->name . "\n"); $person->name(do { chomp(my $temp = $person->name); $temp });
$person->name; $person->name = "Ovid"; $person->name =~ s/Ovid/Juerd/; $person->name .= "\n"; chomp $person->name;

This still throws values in @_ away. But as idiomatically this syntax is used without any parentheses at all, that is not a problem.

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }


In reply to Re: Use method/function signatures with Perl by Juerd
in thread Use method/function signatures with Perl by Ovid

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (16)
    As of 2014-07-22 19:48 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (126 votes), past polls