On Mon, Feb 28, 2011 at 10:48:48PM +0100, Abigail wrote: > On Mon, Feb 28, 2011 at 02:49:38PM -0600, Dave Rolsky wrote: > > I've been working on a new OO tutorial for Perl. This is part of a larger > > goal for the Perl docs to revise all of the existing OO documentation. > > > > My new document is available online for review: > > > > http://urth.org/~autarch/new-pod/html/perlootut.pod.html > > http://urth.org/~autarch/new-pod/pod/perlootut.pod > > > > This document has several goals. First, I want to introduce the reader to > > general OO concepts like classes and methods. Second, I want to explain > > how these are done in Perl. Finally, I want to get them started with > > writing OO code as quickly as possible. > > I've only had time to briefly skim the document, but if I have to summarize > the document, it seems to boil down to "Don't do objects yourself. Use > something that doesn't come with Perl". > Without further judging the content of the document, that just feels wrong. > Not that I have much of a solution though. Hi, I would suggest framing this document as a *supplement* for existing documentation not as a replacement. As an OO beginner just a couple years ago, I recall it was helpful to see object behaviors developed in just a few lines of code. Working through those examples showed me how OO behavior develops. It helped me see how OO behavior is not something esoteric wrapped up in mysterious syntax. In my opinion, exposing the code that makes OO work is not only informative but essential to learning and to understanding what an framework like Moose is doing under the covers! Also, someone learning perl OO will almost certainly need to be able to *read* a vanilla constructor and to understand how bless() works. The tutorial might say it excludes bless because it is described elsewhere, not because a newbie should avoid it. I think the argument against rolling your own OO for production code might be better expressed like this: Due to the desire for such capabilities as introspection, the ability to declare (rather than code) object attributes, to compose classes using roles and to use mature tools that deal effectively with edge cases, many proficient perl coders prefer to use one of the several OO frameworks available. These range from Object::Tiny and Class::Accessor which generate accessors, to Moose, an "industrial strength" solution that is extensively tested and has numerous extensions. Another addition I can think of, might be to include mention of Object::Tiny::RW. It's worth saying that while many useful projects can be accomplished using read-only accessors, this gives careful programmers that ability to assign to object attributes without directly accessing the underlying object. On the subject of accessing the underlying data structure, rather than saying "don't do it", I think it's more reasonable to say "although it's generally better not to do it, you should know how to do it directly. This is what frameworks such as Moose will be doing under the covers:" > Abigail -- Joel RothThread Previous | Thread Next