Slashdot Mirror


Object Oriented Perl

chromatic has brought us yet another pithy programming-book review, this time of Damien Conway's Object Oriented Perl. This sounds like a good book for those interested in not only an overview, but a book that pushes them into at least a few practical applications -- but not one too intimidating to learn from.

Object Oriented Perl author Damian Conway pages 490 publisher Manning Publications, 09/1999 rating 10 reviewer chromatic ISBN http://www.thinkgeek summary Damian Conway demonstrates the elegance of Object Oriented programming in Perl, exposing the flexibility and ingenuity of itsdesign

The Scoop A few common myths sully Perl's reputation in the Object Oriented world: Some claim the functionality is tacked on, while others insist that it is insecure, impure, and obscure. Damian Conway handily dispels these rumors in a gem of a book. Though occasionally delving into black magic, Object Oriented Perl is still accessible to novices. Paraphrasing the preface, this book might very well "[lower] cholesterol... [promote] world peace" -- for wizards and initiates alike. (Or at least raise their skills another level.) The Lowdown The starting point is an introduction to objects and the basic theory behind the OO discipline. This serves as a good overview of the first portion of the book. Following closly is an impressive thirty-page introduction to Perl. As newbies would shortly be overwhelmed, it is not intended as a first look at the language. Rather, it fills in the gaps left by an eclectic education. The chapter ends with a whirlwind tour of more advanced (read, underused) techniques, including the best typeglob discussion I've ever read.

Subsequent chapters narrow the focus and intensify the explanation. Conway first introduces three simple rules of Perl objects: classes are packages; methods are subroutines; and objects are blessed referents. While some forks of the trail are quite exotic (blessing a regular expression into an object?), they're all entertaining and very informative.

Programmatic examples follow an iterative and interactive development process, as is common in technical books. The author states a problem and then writes some initial code using a newly explained feature. Refining the program, he demonstrates other ways of achieving the same goal with less code, more features, and better style. Most examples are creative and fairly easily understood (a CD tracking system, a network model), though some, built from computer-science type examples (a pretty printer, a lexer), may be too esoteric for some readers.

As befitting the Perl philosophy, Conway is not hesitent to break with OO tradition as expressed in languages such as C++, Java, Smalltalk, or Eiffel. (Appendix B discusses language features of each with regard to Perl in compact but enlightening technical fashion.) There's an overwhelming sense of Perlishness about the whole thing, and that shines through on every page. Expect to exploit the language's flexibility to achieve amazing results.

By the end of chapter seven, you'll know everything you really need to know to be an effective and productive OO Perl hacker. Luckily, the increasingly specialized information in the last few chapters is optional. You may never use it, but you'll be better for it. As the most extreme example, the Multiple Dispatch chapter explores three rather exotic approaches I've never seen in a Perl program before (dynamic dispatch tables -- armed with this, you could probably write a window manager in Perl). For the paranoid or the purist, a chapter on encapsulation turns Perl's normally lenient access mechanisms around, protecting data through scalars and secure hashes.

The Summary Superbly organized and excellently explained, this is the definitive book on Object Oriented programming with Perl. Judging from the comments of more qualified experts, we agree that this book belongs on the shelf of any serious Perl hacker. Purchase this book at ThinkGeek. Table of Contents
  1. What you need to know first (an object-orientation primer)
  2. What you need to know second (a Perl refresher)
  3. Getting started
  4. Blessing arrays and scalars
  5. Blessing other things
  6. Inheritance
  7. Polymorphism
  8. Automating class creation
  9. Ties
  10. Operator overloading
  11. Encapsulation
  12. Genericity
  13. Multiple Dispatch
  14. Persistent objects
Appendices
  1. Quick reference guide
  2. What you might know instead

28 of 78 comments (clear)

  1. later by Anonymous Coward · · Score: 2

    So long Slashdot my old friend.
    I won't come to troll you again.
    because the console softly creeping,
    killed my karma while I was sleeping.
    And the flames
    with just remnants in my brain,
    don't remain,
    upon the threads... of Slashdot.

    In flick'ring lights I type along.
    Submit my troll, before to long,
    Letters haloed by my squinting,
    at the rant that I was typing.
    For my eyes were blurred
    by the flash of the cathode beam,
    term'nal screen,
    and all the trolls... on Slashdot.

    And in the fuzzy light I saw
    10,000 zealots, maybe more:
    Zealots karma farming,
    Zealots flaming without thinking.
    Zealots modding posts
    that karma never shared.
    (No one dared,
    disturb the balance... of Slashdot)

    "Fools," said I, "you do not know.
    Honest opinion makes the karma grow.
    They post the rules so that we might read them.
    Meta mod 'cause we don't heed them."
    But my posts
    like trolling karma fell,
    (Oh well...)
    An echo,
    On the threads... of Slashdot.

    Thanks folks, it's been a blast. After a long time under the TM account, I feel it's time I call it quits. The TM
    account was created and used on a bet that a spamming troll could not survive moderation and last more that a
    few week, made even harder by having to do it with an account name as silly as Trollmastah.

    I'm ending my trollish run with:

    * +33 Karma (lowest level I hit was around -20)
    * Due to being over +25, I receive the +1 bonus (kind of ironic)
    * A long run at -2 default.(Well deserved)
    * A console initiated permenant tag which keeps default post at -1 regardless of karma. (sort of a select club)
    * About 50/50 percent positive/negative e-mail(Thank you all)
    * Easily over 100 "First Posts!"(Woo Hoo!)

    Even though trolls are generally discouraged, I did find that trolling is a valuable addition to the /. culture and
    when done without being offensive, vulgar or mean, even trolls can keep positive karma and add not only to the
    culture of Slashdot, but also to the content.

    I'd like to thank Rob, Jeff and the gang at Andover for providing such a cool forum and for putting up with so
    much noise, the daily moderators for participating, and also to the trolls, you add the character which makes
    Slashdot a community.

    Hope you enjoyed the posts,

    Regards,
    TM

    .

    Take all good things in moderation, including moderation.

  2. Great book by sboss · · Score: 2

    two weeks ago I had plenty of time on a plane to read (flying east coast to west coast) and I read the first 7 or 8 chapters of this book. I wasn't planning on it but I just could not put the book down. It was great. I have never done OO before although I understood the principals. After reading this book, I not only understand the principals but I can use them. I am now looking at OO'ng all my code now. It makes sense!

    Scott

    Scott
    C{E,F,O,T}O
    sboss dot net
    email: scott@sboss.net
    I am 39.0% slashdot pure

    --
    Scott
    janitor
    sdn website family
    email: scott at sboss dot net
    1. Re:Great book by Abigail · · Score: 2
      After reading this book, I not only understand the principals but I can use them. I am now looking at OO'ng all my code now. It makes sense!

      Oh, please.

      Damians book is a great book. It shows the real face of Perl OO. How horrible it is. How utterly useless. How it is against both OO principles and Perl principles. Granted, for people who don't know what OO is, or have no experience, Perls OO looks great. But for people who want to use OO for the reasons OO is there: data encapsulation and implementation hiding, Damian clearly shows all the hoops, whistles and bells you need to do yourself before you can do so. In fact, to do real data encapsulation and implementation hiding, you have to do so much work yourself that nothing that comes with Perl standard libraries implements this. Nothing. Nada. Zilch.

      Perls OO is like MacDonalds food. Fast, cheap, and great if you aren't used to anything else. Kids love it. But utterly disgusting for lovers of gourmet food.

      -- Abigail

    2. Re:Great book by Abigail · · Score: 2
      If I want data hiding, I can have it.

      Really? If I write a class, and publish the interface, and you want to use it, how do you know it does data hiding without poking through the source?

      Perl isn't a write-only language you know. It's also about using someone elses code. And Perl OO doesn't make that easy at all.

      Conway shows in his book what the full toolkit of OO techniques is--you can then select what you need for the job.

      Indeed. Write once, use once. Perl OO doesn't at all stimulate code reuse. Any implementation of a class greatly influences how derived classes have to be implemented. That's fine if you want to start from scratch for each project, or are willing to deal with the bagage on a next project. But it doesn't stimulate you to write clean code.

      -- Abigail

  3. An excellent Perl book - with one proviso by Ars-Fartsica · · Score: 4
    I highly recommend this book to anyone who is (or thinks they are) a real perl-head. You will undoubtably learn something new about the language.

    My proviso is this - if you really are interested in object-oriented programming (moreso than simply being a way to write perl, but interested in the methodology itself), then you may want to try Python or another langauge. Perl folks are historically very defensive and perhaps insecure about their OO implementation - Advanced Perl Programming spends chapters explaining to great (and convoluted) pains how Perl's OO approach is superior...but like in Conway's book, you get the notion that it is an apologistic stance.

    Don't get me wrong, I love perl and was on the advance list to get Conway's book. While I have my misgivings about OO Perl, this is still a great Perl book and belongs next to the Camel book on any serious PerlMonk's shelf.

  4. Short, huh? by Mike+Schiraldi · · Score: 2

    Is it me, or was this much shorter than the usual reviews?
    --

  5. To Anyone Who Has Read This One by irix · · Score: 3
    I learned my Perl OO from perltoot and the O'Reilly Advanced Perl Programming book.

    Does this book provide much more than that?

    --

    Do you even know anything about perl? -- AC Replying to Tom Christiansen post.
    1. Re:To Anyone Who Has Read This One by sohp · · Score: 2

      Does it? Ever considered blessing a regex? Bet you didn't know that would work! How about writing an extensible double-dispatch handler? Object serialization? Hell yeh it covers a lot more than perltoot!

    2. Re:To Anyone Who Has Read This One by ftobin · · Score: 2
      Does this book provide much more than that?

      I cannot emphasize it enough. This book doesn't only tell how to create object-oriented Perl, but how to create strong object-oriented Perl. You will not regret getting this book. This book is my all-time favorite Perl book.

    3. Re:To Anyone Who Has Read This One by King+Babar · · Score: 3
      I learned my Perl OO from perltoot and the O'Reilly Advanced Perl Programming book. Does this book provide much more than that?

      Well, you could check out sample chapters on the Manning web-site. I also got my perl OO from the sources you mention, but I was impressed with the Conway samples and would buy the book in a minute on impulse if I could find a local bookstore that stocked it.

      But I guess a large part of my enthusiasm is driven by the fact that this is a book by Damian Conway, the man, the myth, the crazed hacker, the co-author of "C++ Re-syntaxed", the author of the Coy module, and so on. Seriously, I figure I'd give the guy like $10 if I ever met him in person, so why not just buy all his books and let him have the royalties instead?

      --

      Babar

  6. This book revamped my Perl OO module creation by ftobin · · Score: 3

    If you write serious Perl modules, get this book. I cannot emphasize this enough. I am an author of a couple CPAN modules, most importantly GnuPG::Interface, and I must say that this book entirely revamped my object-oriented Perl module design.

    It is the best Perl book I have (and I have quite a few). The most important thing I learned from this book was existence of a very important module, Class::MethodMaker, again available from CPAN. That module and this book will teach you how to write maintainable, powerful modules. It teaches tieing in a clear manner, what modules are available for use, and what pitfalls to avoid.

    I have to repeat this again: if you are a serious Perl module writer, get this book!. You will not regret it!

    1. Re:This book revamped my Perl OO module creation by drix · · Score: 2

      I'm curious how you learned OOP. I'm a self-taught Perl/C hacker who has just never been able to make the leap to object orientation. I know that one of the major benefits of OO is that ideally it is easier to program in because the coding process for objects is a bit more like how we think. For me though, procedural programming just clicks. It's way easier and less muckier than OO, and wierdly enough a lot more intuitive. Mebbe I've just trained myself to think 'procedurally' after all these years. I gather it takes a long time for OOP to fully sink in? It doesn't sound like something I could just sit down and learn, effectively. At any rate, I'm starting EECS at Berkeley next year, so I'm sure after being beat with it for 4 years I'll figger some things out...


      --

      --

      I think there is a world market for maybe five personal web logs.
  7. OO or structured OO? by jstepka · · Score: 2

    Everyone knows C++, but not everyone knows OO in the ture fashion. Does this book take you from the design process with an OO architechure which will really drive the OO development or does it just use object while maintaining a structured core?

    A good place to check out OO design paterns an software would be www.rational.com.

    --
    Justen Stepka
    1. Re:OO or structured OO? by randombit · · Score: 2

      Everyone knows C++, but not everyone knows OO in the ture fashion. Does this book take you from the design process with an OO architechure which will really drive the OO development or does it just use object while maintaining a structured core?

      I think it would be very hard to really learn OO just by learning languages like C++, Perl, or Objective C, where OO features are basically attached onto an existing procedural language. I've been programming C++ about 3 years and still haven't figured it all out (getting there). Maybe better luck is to be had with languages like Python, Smalltalk, Simula, and other such languages [though I have a feeling it wouldn't, for some reason... dunno]

      Design Patterns, by Gamma et. al. is probably the book that has helped me with OO the most; it has code examples in C++ and Smalltalk but you really don't need to know either language to understand the book (I have no clue about Smalltalk), as they explain everything in English very clearly, and then use the code just as examples of their methods. I highly recommend it anyone doing OOP in any language.

  8. Shades of 'me too' ... by LizardKing · · Score: 2

    I also wondered whether this book would give me anything above and beyond Advanced Perl Programming.

    And for those who are berating Perl for not being a 'true' OO language, take a look at Objective C, which welds Smalltalk like OO features onto a base language in much the same way that bless() does in Perl. And before you knock Objective C simply because the behemoth that is C++ is currently more
    popular, take a look at Mac OS X and OpenSTEP whose API's a largely Objective C based.


    Chris Wareham

  9. Re:Perl != OOPL by keyeto · · Score: 2

    Well, not quite. Perl manages memory using reference counting, so circular data structures will hang around until the Perl process dies, even if there are no references to the circular data structure left anymore.

    This is less serious than the sort of memory leaks you typically get in C, where you are trying to use a reference to a data structure that has been deallocated, or where you never deallocate a data structure nothing can has a reference to. In Perl, the former is never occurs, but the latter does.

    However, it's still rather weak, and should be updated to at least perform proper mark and sweep garbage collection, like Ruby, Java, Python, Eiffel, and many others.

    A little more on-topic though, I don't like Perl much, but its object orientation is rather well tacked on, even if it's only been tacked on, rather than being a fundamental design decision. In truth, it's the only aspect that encourages me to use the language, whereas there are many aspects that discourage me, not least the way it's not at all easy on the eye.

    Furthermore, it's a mistake to think Perl has multiple inheritance, since it is only possible call the constructor of one superclass before blessing the result as an object of the class you're defining. The "multiple inhertance" is much more like the interface mechanism in Java, with the added advantage of being able to provide method bodies.

    --
    -- "This is the Space Age, and we are Here To Go" - W.S.Burroughs
  10. I scanned this book at B&N, and passed.... by nellardo · · Score: 2

    I didn't need the OOP theory (having written a book myself that taught OOP to people without any prior programming experience). I didn't need the Perl introduction (having just forced myself to learn perl after avoiding it for being the blight of a PL that it is (albeit useful) in order to change slash). So what did it it offer?

    • Using Perl packages as objects? Nope. Got that from the Ostrich.
    • Subroutines as methods? Nope. Second thing I did (after twinking a calendar package to use slash's user table and cookies) was create a Slash::Sql wrapper around the "do/execute/fetchrow" nonsense of DBI.
    • Persistence? Nope. Third thing I did was make a Slash::Object class, which could read itself from an Sql database, and had an AUTOLOAD corresponding to the columns in the table.
    • Multimethods? Okay, this was slightly useful. I caught from skimming the book that there was a multimethod package on cpan. Went there, did a search, then did perl -MCPAN -e "install Class::Multimethod" and I was done.

    Perl's syntax is often opaque (especially if you didn't already know all the Unix utilities, shell scripting langs and programming langs it is based on). It ispowerful, but this book didn't quite seem to get it all. Closures, non-class-based inheritance (a la Self), or even some more useful examples? (the fourth thing I did was make a Slash::Handler class to interface to Apache, automatically placing query args or form input into fields on itself - subclass and override "handle" to decide what to do) (fifth thing was a subclass of Slash::Handler to use Text::Metatext to generate the page).

    A nice enough book, but I think I'm gonna have to write one myself before I see one I really like :-)

    --
    -----
    Klactovedestene!
    1. Re:I scanned this book at B&N, and passed.... by msuzio · · Score: 2

      *shakes head*

      I do not think (at this point in time) Perl syntax can be considered opaque. It certainly has plenty of strange things as a legacy of how it has grown over it's lifetime, but is this chunk of code so unclear?

      use DBI::DBD;

      my $dbh = DBI->connect('dbi:Oracle:', 'fooboy/foo@database');

      my $file = IO::File->new($inputFileName);

      while($in = $file->getlines()) {
      $dbh->execute($in);
      }

      ..seems pretty easy to understand to me, once you know the basics that DBI is a database interface layer and IO::File is an object to do IO from files.

      In it's basic structure and flow of control, Perl is pretty much the same (to me, at least) as it's close relatives (C, C++, Java). It lacks a lot of the complexities of those (and has plenty of it's own), but it's *not that hard* to learn!

      I think, for instance, that Perl is a perfectly easy language to teach in a 100-level CS "Intro to Programming". No prior experience needed.

    2. Re:I scanned this book at B&N, and passed.... by nellardo · · Score: 2

      So, msuzio replied to my post, in which I called Perl syntax "opaque":

      I do not think (at this point in time) Perl syntax can be considered opaque. It certainly has plenty of strange things as a legacy of how it has grown over it's lifetime,....

      First off, let's keep things in context. I said Perl syntax was opaque if you didn't already know the various things it was vased on, which as most Perlmonks know, includes sed, awk, C, sh, csh, C++, Lisp, and Scheme. (for those that don't think Perl draws anything from Lisp or Scheme because it doesn't have all the parens, try looking at "anonymous subroutines" - aka closures (which is what Wall rightly calls them))

      Second, opacity of Perl syntax is is obviously something that reduces as you become more familiar with the language. This is complicated by the fact that Perl syntax allows several different ways to do any one thing (a design goal of Perl, of course), which results in a language that lends itself to extreme obvuscation. Consider - a Perl obfuscator could run through Perl code stripping out many local variables, replacing their use with nested expressions, $_, and the like. Flatten some of the subroutines, and make all variable names no more than two characters. A lot of Perl code looks just like this when it is first written - it works but try to get anyone other than the original author to do anything with it. Yes, you can write more engineer-able code in Perl, but you can also write object-oriented assembler.

      but is this chunk of code so unclear?
      use DBI::DBD;
      my $dbh = DBI->connect('dbi:Oracle:', 'fooboy/foo@database');
      my $file = IO::File->new($inputFileName);
      while($in = $file->getlines()) { $dbh->execute($in); }

      ..seems pretty easy to understand to me, once you know the basics that DBI is a database interface layer and IO::File is an object to do IO from files.

      I'm guessing you have experience in other Algol-based languages, and with some form of shell scripting. Even so, consider the (equivalent):

      use DBI::DBD;
      for (my ($d,$f)=(DBI->connect('dbi:Oracle:', 'fooboy/foo@database'), IO::File-<new($i);$->getlines();) { $D->execute($_); }

      Now suppose you don't know what DBI is. or IO::File. Start throwing regular expressions around and things can get really hairy. This example didn't even start messing with mixes of arrays, hashes, and references.

      In it's basic structure and flow of control, Perl is pretty much the same (to me, at least) as it's close relatives (C, C++, Java). It lacks a lot of the complexities of those (and has plenty of it's own), but it's *not that hard* to learn!

      Which complexities does Perl lack?

      • Strong typing? How many times have you mistakenly put a hash in a scalar context (or vice-versa)? The code goes happily along until, later, you try to look up something in what you thought was a hash (after all, you assigned it a hash), only to get an error that you can't coerce a scalar to a hash?
      • Inlines? Nested expressions in Perl and anonymous subroutines got that beat.
      • Direct memory access? Tell me that pointer arithmetic is inherently more complicated than the pointer chasing involved in a typical hash/array mix in Perl.
      • Templates? Yeah, Perl lacks those, but it lacks those because it lacks strong typing (see above).
      • Parameters? Ever do my ($a,$b) = shift; by mistake? After having had one parameter and needing to add a second? How about mixing shift, @_, and other list operations?

      I could go on, but my wrists are starting to hurt.

      I think, for instance, that Perl is a perfectly easy language to teach in a 100-level CS "Intro to Programming". No prior experience needed.

      Sounds like you've never actually taught such a class. Try explaining parameter passing. Now try explaining scoping rules. Do you really think you can do that with Perl without driving all your students away?

      It may not be so hard for an experienced *nix hacker to learn, but anyone else? C'mon. Be realistic.

      --
      -----
      Klactovedestene!
  11. Re:If OO is so great, why is bulk of GNU/Linux in by Anonymous Coward · · Score: 2
    And don't say OO is best for large scale projects. I know of no larger scale project than GNU/Linux. Surely if C++ and OO was such an advance over C it would have totally replaced nearly all C code by now.

    Much of the code is old (this include the GNU tools, most of them were available 10 years ago), and, more importantly, is written to be portable. And also, rewriting an application in C++ bring few benefits.

  12. Re:Perl != OOPL by Abigail · · Score: 2
    No Data Hiding? Not fammiliar with closures are you? They make it quite easy to hide your data.

    Care to point out a module in the Perl standard library that uses closures for objects? Or a well known CPAN package?

    I hear it all the time. Sure, with Perls OO you can do foo. It's easy! Just bend over backwards this way. Except that noone does it. So, you still can't use someone elses black box, cause noone finds it easy enough to make their box black.

    -- Abigail

  13. Re:Perl != OOPL by Abigail · · Score: 2
    So you are blaming the language for the faults of the people who use it? (ie being lazy).

    In this case, yes. Perl wants the programmer to be lazy. But the lazy way to do OO in Perl is using blessed hash references (and 99% of the examples and code out there uses blessed hash references).

    And closures aren't really so hard as I would call them "bending over backwards".

    I have no problem using closures. Perhaps you might want to look at my OO::Closures package on CPAN that does OO without using bless (and has full data encapsulation and implementation hiding). However, use of closures for objects is extremely rare - apparently it's too difficult for 99.99% of the Perl coders out there.

    Besides...not everyone cares about black boxen. OOP is nice, if thats what you like.

    Well, if you don't want to use OO, there's no point in discussing here. My point is that if you want to use OO, Perl isn't a suitable language. 99% of the code that's labelled as OO in Perl is nothing more than abstract datatypes with weak binding. It ain't OO; a '->' token doesn't make OO.

    You don't like PERL...don't use it.

    Well, it's Perl, not PERL. And I do like Perl. I just don't like the monster they call OO-Perl, because it's neither Perl, nor OO.

    -- Abigail

  14. I, too, learned from pertoot and the leopard book by freeBill · · Score: 3

    And I got a lot from this book.

    First off, let me get my biases set forward: I believe strongly in OOP. I believe strongly in OO Perl. And I believe strongly in this book, in Damian Conway (who is an excellent educator from Australia), and in the approach he takes to OOP in this book. I believe that OO is an evolving discipline which changes every year. I believe that many OO implementations do a better job of reproducing a snapshot of where OO theory may have been at any one point.

    But it is clear to me that Perl's there-is-more-than-one-way-to-do-it (TIMTOWTDI) philosophy does a better job of presenting a dynamic model for implementing any level of OOP that you would like to use for a particular problem. This means you can use it to do true OO programming no matter what you define as "object oriented." This means it can do what you want to do today and what you may not yet know you will want to do tomorrow.

    Perl does not force you to do any of it, but it allows you to do whatever you would like. You may have to do some of the work to set it up, but that's the price you pay for the flexibility it allows. Anyone who tells you Perl cannot implement some important aspect of OO probably is doing nothing more than admitting their own ignorance.

    Those biases out of the way, the question is: Does this book take it beyond perltoot and "Advanced Perl Programming" (the leopard book)?

    The answer is "yes," but it may not be in the way you are looking for. This book is written very much in the spirit of TIMTOWTDI. Each of the chapters lays out all the ways one might approach the subject of the chapter. This gives a variety of solutions to every problem and a very thorough understanding of every issue. If you want an OO system that just tells you the one way you have to do it, then this is not the book for you. But then, Perl is probably not the language for you, either.

    Most of the chapters present their solutions in the form of a kind of limited metaclass (essentially abstract classes from which your classes can inherit to acquire the desired functionality). Those familiar with many of the modules on CPAN will recognize this approach.

    In general, I found this book to be exactly what I needed to go beyond pertoot and the leopard book. But I would emphasize that I almost never use Damian's code exactly as he presents it. On the other hand, since I have read this book, I have never written a base class which was not based on what I learned from Conway.

    It is clear that Damian knows a great deal about OO theory and teaches it well. (This book is also every bit as funny as the camel book.)

    The multimethods chapter is a definitive exploration of multiple inheritance. I never use multiple inheritance, but if I ever try it will be based on the CPAN module he explains in this chapter. As has been pointed out elsewhere, this information can be obtained from CPAN as well (but you lose the excellent explanation available here) or from the paper Conway read at last year's Perl Conference.

    Summing up: If you understand what I mean by a dynamic model of OO and want to try it, Perl is a good place to do it. If you want to try but are not sure how to implement it, this is the book for you. If you want a static model of OO that holds your hand and makes you behave, then OO Perl is not for you and you should not waste your money on this book.

    --
    Eternal vigilance only works if you look in every direction.
  15. Re:Contradiction in terms? by acb · · Score: 2

    Obsfuscated Perl is the fault of the programmer, not the language. You can write
    gross code in any language. I agree that some languages do make it easier to write obsfuscated code, but ultimately the programmer is still one to blame.


    Though Perl makes writing neat, easily manageable code on any large scale more of an effort than other languages. And the most carefully written Perl program will still look messier than an equally carefully written program in, say, Python (or Smalltalk or [insert true OO language here]).

    Perl was not designed for system development or large-scale coding. You can use it for that, and at some things it excels (processing data, for one), though it is a suboptimal choice. (Have you ever had the feeling of returning to a large Perl project you wrote months ago, say a complex CGI system or such, and almost getting a headache from looking at it?)

    If a language makes good design a chore, that is a fault in the language.

  16. Re:OO is for representing things as objects. by Abigail · · Score: 2
    As for data encapsulation, which is OO, how does perl's OO not do this?

    Simple. The typical way (yes, I know how it can be done differently, but let's just ignore the 1% code out there that does it actually different) of making a Perl object is with a blessed hash reference. All your variables associated with that object are put in a hash reference.

    Now you want to inherit a class with such an object. Where are you going to put your variables? Right. In the same hash reference. No data encapsulation. No implementation hiding. No private variables.

    Or to summerize it: no OO.

    Data hiding is simply a matter of public vs. private APIs. You anounce your public API, you don't anounce your private API, and you make the distinction that anyone using the private API gets what they deserve.

    The problem is, with Perl, to be able to successful inherit someone elses class, you have to know how the class implements objects. You cannot treat the implementation as a black box and only look at the public API.

    Hence, no real OO.

    If you really can't trust your programmers enough to follow the rules, make the damn thing a tcp/ip server or a corba service.

    It has nothing to do with trust. It has everything to do with programming convenience. I want to be able to take something, obey its API, and then, regardless of what I do, I should not be able to accidentely trample on someones elses variables, or be forced to implement classes the same way as the inherited class was implemented. But the language doesn't give that to me by default; only if I'm lucky and use something whose author went to great trouble keeping their space clean I can do that.

    Again, yes, I know it's possible. Damians book shows it's possible. The problem is, Perl's OO is so awkward, it ain't happening. And that's the language fault - not the programmers.

    -- Abigail

  17. Re:"Object Orientated Perl" LOL! It's a joke right by elflord · · Score: 2
    Perl is not the language of choice for anyone interested in doing some serious OO programming,

    What do you mean by "serious OO programming" ? The OO features of perl are quite useful, even if they are "tacked on".

    who wants a whole file taken up by every class no matter how small?

    Sorry, you've lost me. IIRC, you can put multiple packages in one file.

    which is invariably unreadable code which looks something like @foo[--$bar]=~s/$^[3ffkj3n43][[543!x-djf-2]]£jds/% fjfj3[243]fdkjr93432[] unless -e $baz

    All this proves is that you have no idea how to write comprehensible code. It's not perl's fault that you're a lousy programmer. You can ( by using a flag ) put white spaces in your regular expressions in the event that you ever do get a regular expression that long and ugly. BTW, can you explain why you think python's regular expressions are more readable than perl's ? How would you do the thing you did above in python ?

    Just look at the Slash code for a perfect example, and that's not even got any OO!

    Well duh ! That's kind of the point. If you use OO, you can write much cleaner code in perl. Not only doesn't the slash code use OO, it's not terribly clean. You're fooling yourself if you really think that migrating to python automatically relieves you of the obligation to write decent code.

  18. Re:Contradiction in terms? by acb · · Score: 2

    I return to large perl projects with no problems at all.... Which is why I maintain that writing managable code is the burden of the programmer and not the language.

    Though the choice of language can make manageability easier or harder. Manageability is built into the structure of, say, Python, and comes naturally from it. In Perl, however, writing manageable code requires more effort and discipline; it requires the programmer to specifically concentrate on the task of arranging their code in a manageable way, rather than the myriad other ways Perl is just as happy with.

    I'll grant that if you are a real OO purist, Perl and C++ aren't for you.

    Oddly enough, I don't find C++ to be anywhere near as messy as Perl. Though I wouldn't call it a proper OO language either; it's more of a code generation tool.

  19. Re:OO is for representing things as objects. by Abigail · · Score: 2
    You could do that if you want, to.

    Yes, I know Perl lets you have that. I know Perl very well. And as I said before, I know that if you do a lot of work, you can have implementation hiding and data encapsulation. But you didn't understand my point.

    Once again: Perl is making easy things easy, and hard things possible. But within an OO framework, implementation hiding and data encapsulation should be easy. Doing everything with AUTOLOAD and dispatch tables isn't easy. It's hard work!

    Whatever floats your boat!

    Indeed. Keyword: your. OO is about code reuse. Someone elses code. But, since Perl lets you make objects in a myriad of ways, and makes the implementation part of the API, whether you want it or not, Perl is unsuited as an OO language.

    You cannot treat the implementation as a black box and only look at the public API. Yes you can - use a tied hash interface and everything suddenly has to go through an access function! Not awkward in the least.

    See, there you said it. use a tied hash. If I want to inherit someone elses class (that's what OO is about, code reuse, remember), and that someone uses just a hash reference (like almost everyone does), you're screwed. That's what I mean with you cannot treat the implementation as a black box. Saying yes you can if it was implemented this and this way is just proving my point; not disproving it.

    -- Abigail