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

comment on

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

Granted, a.b = 12; is much nicer looking than a.set_b(12); or a.set_b = 12
(Other post: If it's supposed to be an assignment it should look like an assignment, and setting a property or attribute is an assignment no matter how it's mediated under the hood.)

FYI, in case you didn't know about it already, Attribute::Property makes a->b = 12 work in Perl 5. From its synopsis:

my $object = SomeClass->new(digits => '123'); $object->nondigits = "abc"; $object->digits = "123"; $object->anyvalue = "abc123\n"; $object->anyvalue('archaic style still works'); my $john = Person->new(name => 'John Doe', age => 19); $john->age++; printf "%s is now %d years old", $john->name, $john->age;

When modifying a value using an accessor method (which we dubbed 'archaic style'), things get ugly:

Old: $john->age($john->age + 1); $john->name->(do { (my $n = $john->name) =~ s/Doe/Smith/; $n }); New: $john->age++; $john->name =~ s/Doe/Smith/;
Having these things1 built-in in Perl 6 will make me happy.

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

1 The things that are called 'properties' in Perl 5 jargon2, but 'attributes' in Perl 6 jargon. Perl 5's 'attributes' are 'traits' in Perl 6. (IIRC)
2 But not officially. They're often called 'attributes', but we should discourage that, because 'attributes' are already something else. Attributes are relatively new, though, so we can't blame writers of older documentation.

In reply to Re: Re: •Re: Why get() and set() accessor methods are evil by Juerd
in thread Why get() and set() accessor methods are evil by synistar

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2022-12-05 07:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?