Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

OO and Perl

by Anonymous Monk
on Mar 31, 2011 at 02:07 UTC ( #896532=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I like to study real world objects and their relationship using Perl, so I can write OO code rather than just procedural code. I also like to know, if I am on the right track in doing so. Where should I start?


Replies are listed 'Best First'.
Re: OO and Perl
by schwern (Scribe) on Mar 31, 2011 at 05:40 UTC

    There are two camps of learning Perl OO. The first is that you should learn all the various pieces of building an OO system and grab modules off CPAN that do individual things. This is the traditional way of doing OO in Perl.

    The other is to start with Moose which is a great system that does everything you need.

    I am strongly in favor starting with Moose. Why? Several reasons. OO is all about abstraction and composition and interfaces. It is about burying how your code does it's work and focusing on just that it does what it says it does. Digging into the nitty gritty details of building an OO system and picking and choosing your pieces is the antithesis of that.

    Moose has everything you need all in one package. Roles, attributes, introspection... it's all there. The bits and bobs on CPAN? They each implement part of the problem. Maybe they work together, maybe they don't.

    Moose is very heavy, but if it's too heavy for you there's Mouse which has no dependencies. They interoperate well and there's Any::Moose to decide between them.

    TMTOWTDI but Moose is a pretty good one which Perl 5 is (finally) converging on. You can write a Moose class and be pretty sure any given Perl programmer will understand it. If they don't, they just have to learn one module... one they're going to have to learn anyway. If you need advice, you can get it. If you write something by hand or pull bits off CPAN, who knows if it's a module someone is familiar with.

    Finally, the stuff in the core docs is really, really, really out of date and gives some bad advice. It's far too focused on HOW to build an OO system and not what you should be doing with it.

      BTW how is Perl5i going?
Re: OO and Perl
by davido (Archbishop) on Mar 31, 2011 at 02:24 UTC
Re: OO and Perl
by wind (Priest) on Mar 31, 2011 at 02:17 UTC
Re: OO and Perl
by luis.roca (Deacon) on Mar 31, 2011 at 03:11 UTC

    Aside from the resources mentioned above, you may want to take a look at * Damian Conway's Object Oriented Perl from Manning. I've been reading it the last few weeks and it's going a long way in clarifying terms that kept popping up more and more for me while learning Perl. (ie: polymorphism and inheritance)

    An additional approach is to look at another language that puts as much if not a greater emphasis on object oriented programming. Learn the general OO principles and reinforce that knowledge by comparing how other languages implement them to Perl. * This is part of a suggestion offered to me by a few friendly monks (right now I'm applying the advice in comparing functional languages to Perl).

    Good luck!

    * Others may be turned off by the 1999 publishing date but I feel pretty good about what I've learned so far.

    * The thinking is that in learning various languages that are different stylistically you gain greater overall knowledge of programming practices and concepts.

    "...the adversities born of well-placed thoughts should be considered mercies rather than misfortunes." Don Quixote
Re: OO and Perl
by stonecolddevin (Vicar) on Mar 31, 2011 at 05:18 UTC

    Three thousand years of beautiful tradition, from Moses to Sandy Koufax, you're god damn right I'm living in the fucking past

Re: OO and Perl
by sundialsvc4 (Abbot) on Mar 31, 2011 at 14:28 UTC

    There are lots of abused buzzwords in this business, and “OO” is one of the worst.   You can’t “just use the word” in conversation and assume that the person to whom you are speaking has the same meaning for that word.

    I think it’s also worth mentioning that “studying real world objects and teir relationship” is ... a useful metaphor, but one that only goes so far, such that it can easily be taken too far.   It can become a religion.   You can cling to it to the point that, having written a chunk of code and now coming back to look upon it later, you can no longer (readily) say exactly what it does.   You can write code that becomes un-maintainable in actual practice because of a web of “inherited” and “mixed-in” behaviors that tie everything together like a gigantic ball of string.   As you study these topics, stay well grounded.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://896532]
Approved by ww
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2017-12-16 05:51 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (449 votes). Check out past polls.