http://qs321.pair.com?node_id=310487


in reply to Why get() and set() accessor methods are evil

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: 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