Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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 => '', plp_site => '', 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

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 taking refuge in the Monastery: (8)
    As of 2018-07-16 14:58 GMT
    Find Nodes?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

      Results (342 votes). Check out past polls.