Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^10: OO automatic accessor generation

by WizardOfUz (Friar)
on Nov 13, 2009 at 15:04 UTC ( #806967=note: print w/ replies, xml ) Need Help??


in reply to Re^9: OO automatic accessor generation
in thread OO automatic accessor generation

I'm sorry. The first paragraph of my previous post was an (obviously failed) attempt to be humorous. I absolutely agree with everything you have written in your last post. I just believe that we should encourage beginners to learn the basics of Perl OOP instead of blindly referring them to Moose. I've seen this kind of dialogue one too many times:

ImaNewbie: Hi! I've just started using Perl and it's great! I want to get into this OO thing now. I've written some code, but it doesn't work and I really need your help ...

... 200 lines of code which took ImaNewbie two hours to write ...

FatOldMonk: Moose.


Comment on Re^10: OO automatic accessor generation
Re^11: OO automatic accessor generation
by stvn (Monsignor) on Nov 13, 2009 at 19:05 UTC

    FatOldMonk++

    Seriously though, it could be argued that sending people to learn the old, tedious way of Perl OOP first will drive some new users away. Especially with languages like Ruby and Python out there which have nice OO out of the box. Don't get me wrong, I totally think that you should learn your roots, but Perl OOP not only imposes a lot more work but can teach really wrong headed behavior (due largely to its extreme minimalism), just look at like the last 2/3rds of Damians OO book, it is full of overly clever tricks that should never be done in the real world. At some point people just need to get work done.

    -stvn
      just look at like the last 2/3rds of Damians OO book, it is full of overly clever tricks that should never be done in the real world. At some point people just need to get work done.

      Maybe it's been a while since you actually read Damian's OO book, because that's not how it seems to me.

      Of the 14 chapters, the first two give good general introductions to the concepts of OO and the bits of Perl you need to understand to understand OO Perl. The nest five explain the basic way Perl OO works (though Chapter 5--on blessing non-hashes--has a lot of stuff that most developers would never need). Chapter 8 explains two outdated approaches to class creation (i.e. earlier and more easily understood versions of what Moose does now). Chapter 9 explains ties (which certainly are overly clever). Chapter 10 looks at operator overloading (and the last third of the chapter actually counsels against clever tricks). Chapter 11 covers several outdated approaches to encapsulation (which I know you don't consider important, but some of us do). Chapter 12 works through a simple example of polymorphic design. Chapter 13 looks at multiple dispatch (a "trick" so useful that it's now fundamental to, and used everywhere in, Perl 6). The final chapter shows a whole lot of definitely overly clever tricks for creating object persistence mechanisms.

      So there are clearly "overly clever tricks" in chapters 9 and 14, and arguably some in parts of chapters 5, 11, and 13. By my count that's about 100 pages out of 490, or around 20%. Instead of 2/3 of the book being wrong-headed, it seems to me that the first 40% of it is an good solid introduction to the way OO Perl actually works; and that most of the rest of consists of useful, but non-essential, explanation too. Not bad for a book written a decade ago.

      Personally, I'd rather have developers who have read Damian's OO book and therefore understand the underlying Perl OO mechanisms that Moose uses (or sometimes replaces), than have developers who don't understand how Perl OO actually works and just treat Moose as a magic wand.

        So by your count out of 14 chapters six document outdated or overly tricky features of the Perl OO model (5,8,9,10,11,14). while Five are straight forward useful (1,2,3,4,12) ... and one is useful but advanced (13).

        By my count that's 35% of the chapters that are directly useful to a Perl5 developer today. Those chapters are also front-loaded. Not bad for a flippant remark.

        As for encapsulation, I've listened to stvn's rant about it more than most people. The point isn't that encapsulation is bad, the point is that going out of your way to enforce encapsulation in a language like Perl is simply adding complexity with no benefit. Why double your code when a simple rolled up news paper across the nose is sufficient? "Bad Programmer, No Cookie!"

        That said I'd agree with you, I'd rather have a developer who read Damian's OO book for the 1/3 that is *useful* about OO Theory ... and then used Moose ... rather than a developer that doesn't understand OO at all and things Moose is a Magic Bullet. But given a raw programmer, I'd rather have them learn good OO theory using a proper tool like Moose than I would have to re-teach them all the things I had to forget when I moved from raw Perl OO to Moose three years ago.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://806967]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2014-08-23 08:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (172 votes), past polls