Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

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

I wrote-up something along these lines a while ago for perldesignpatterns.com. Other things have been written in the past too. Off the top of my head, the major gripes people have with put-get accessors (not lvalue or tied interface) are:
  • -> becomes the only useful operator. + becomes foo->add() or foo.add().
  • Side effect of above: incrementing or any += style operator becomes particularly painful
  • The rich interfaces of hashes and arrays is lost when implementing datastructures as objects, an extremely common case
Like functional programming, object oriented programming is more a state of mind than a set of tools. There are powerful motivators for people to drop the features of Perl for a far more simplistic language that offers a clean, consistent object library and strict checking. These kinds of projects are seldom done in Perl - projects with numerous programmers. Attempting to do these large projects without the natural inter-programmer boundaries that interfaces afford is every bit as painful as losing hashes, automatic stringification, and so on. Well, it need not be such a choice: operator overloading, tied interfaces, and lvalue methods collectively allow you to present a portion of an OO interface as an array, hash, or so on. An early on accepted RFC for Perl 6 (perhaps this has changed since then) asks that hashes iteractors be reset explicitly with a sort of %hash.reset() type thing. Things like exists() would be made into methods as well rather than polluting the core namespace. Hashes have a rich interface, but as rich it is, it will never be rich enough. Your object will present some of its interface masquerading as core Perl features, but after a point, you must commit to an API, and you should do this carefully, thoughtfully, and knowledgeably. This is a topic unto itself. Designing anything that pases the test of time boils down to becoming a history major, studying many falls of many civilizations. In other words, just because you can avoid OO interfaces for a while doesn't mean you should forever, or that you need be any less skillful with them just because you're writing Perl instead of Java.

-scott

In reply to Re: Why get() and set() accessor methods are evil by scrottie
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 perusing the Monastery: (4)
As of 2024-03-30 08:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found