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

5 of 78 comments (clear)

  1. 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.

  2. 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 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

  3. 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!

  4. 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.