Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hello synistar

Months ago I wrote a meditation on the involuntary encapsulation violation; even if I had three nice answers, I still think that that kind of implicit ability of modifying the internals of an object without using accessors is a bad thing. What I think is wrong in an accessor like get_list is that you are passing back to the caller a reference to an internal structure of the object. Do something like this:

my $x = $obj->get_list ; $x->[3] = 'surprise!' ;

...et voilà!: you changed the object without using set_list. I agree that the example above is really-bad-code, but there is a lot of it around...

Strictly speaking about your meditation, I like best accessors that have the ability to get/set their values, or read-only ones, or write-only ones. After reading Advanced Perl Programming I started using get/set methods, but after a short time I found them really annoying...

Ciao!
--bronto


The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
--John M. Dlugosz

In reply to Re: Why get() and set() accessor methods are evil by bronto
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?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-03-29 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found