Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Object oriented Perl and Java: A brief examination of design.

by hippo (Curate)
on Jan 29, 2014 at 09:49 UTC ( #1072471=note: print w/ replies, xml ) Need Help??


in reply to Re: Object oriented Perl and Java: A brief examination of design.
in thread Object oriented Perl and Java: A brief examination of design.

For clarity, instance variables are defined within methods and while in many classes they are all defined in the constructor (method) this is not always so.

Most OO Perl programmes are today written using Moose, Moo, Mouse, etc.

I'm sure that many are - but "most"? Do you have any data to back this up? I've been using Moo on and off for a couple of years and have just returned to it in the last week or so. Building a class using the current docs I find that my version of the module is now out of date but that doing the upgrade requires a whole heap of work because of all the (mostly new) dependencies which also serves to reinforce how heavy it is, despite a contrary statement of its aims.

We don't all write daemons or other persistent code where startup time is not a consideration. We don't all have swathes of memory at our disposal to fill with cascades of module dependencies. We don't all have deployment environments where module upgrades can be made with impunity. At least, not all the time :)

The "modern" OO module frameworks such as these are a boon for sure, but they are not a panacea. And while they are probably the simplest, easiest introduction to Perl OO for java programmers like the anonymous OP, if they hide what's going on under the bonnet (or the programmer never thinks to look) the lack of appreciation of the OO core will always hold the programmer back.

Those of us who can remember the introduction of OO into Perl will have been writing such bare-bones code for a decade or more. Many of us still do. While the resulting source may have a little too much boilerplate for some tastes, it will be fast, light and portable.

In summary, it's horses for courses. Learn both approaches, take the best from each and choose from that experience which to apply in relevant situations.

I'll get off my soapbox now. Thank you for listening.


Comment on Re^2: Object oriented Perl and Java: A brief examination of design.
Re^3: Object oriented Perl and Java: A brief examination of design.
by Athanasius (Monsignor) on Jan 29, 2014 at 13:20 UTC
    For clarity, instance variables are defined within methods and while in many classes they are all defined in the constructor (method) this is not always so.

    I guess I should have said: Mostly, instance variables are defined within a constructor, or within a method called (directly or indirectly) by a constructor. But in some (rare?) cases, instance variables are recycled (via constructors and destructors) from an object pool created in a BEGIN block and stored in a class variable (array or hash) at package scope. (Am I still missing something here?)

    I'm sure that many are - but "most"? Do you have any data to back this up?

    No, that was merely my impression from reading PerlMonks! But the point I wanted to get across to the OP was this: If you come to Perl from an OO language like Java or C++, Perl’s core OO features may appear underwhelming. But Moose and related modules are in common use, and provide many of the OO features you were expecting. So by all means learn how OO works in Perl, but don’t judge “Perl OO” by its core mechanisms alone.

    I'll get off my soapbox now.

    The issues you raise are worth discussing, and your points are well made.

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re^3: Object oriented Perl and Java: A brief examination of design.
by stonecolddevin (Vicar) on Jan 29, 2014 at 19:43 UTC

    Moo is pretty light and is fairly suitable for most non-swaths-of-RAM-situations. I've used it plenty for small utility scripts when I need OO. The slight tradeoff in speed is definitely made up for in readability.

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-08-29 11:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (280 votes), past polls