Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: perl OO - to use or not to use

by graff (Chancellor)
on Sep 14, 2003 at 21:57 UTC ( #291450=note: print w/replies, xml ) Need Help??

in reply to perl OO - to use or not to use

1) Are there instances where OO perl is the only choice?

No -- just as there are no instances where perl itself is the only choice. But there are cases where programmers are much better off using OO perl, as evidenced by the many OO-style CPAN modules that have become essential tools in many a perl coder's daily activities. While a number of posts here (including some of mine) have defended the legitimacy of procedural coding and carped against "OO or die!" fetishists, there's no denying that OO should be the preferred approach for many tasks.

2) Say you've written a pretty large program written mostly in proceduaral perl. Can you easily re-write that program in OO perl later if you choose to?

Maybe a more pertinent question might be "can you write an app using just procedural syntax and structure, but do it in such a way that it could look like (and could be transformed pretty easily into) a `real' OO design?" Well, yes, sort of; to start with, use strict, and don't use any global variables; as you find that you need some set of subroutines that all manipulate the same data in various ways, group those subs together in one file (or inside a set of curly braces), and put the data in there with them. This is the start of building an object -- all it needs is a package statement at the top (to declare a name space), and a sub called "new" that includes a "bless" statement, and presto, it's an object. (Well, there might be a little more to it than that, but not much.)

update: I keep forgetting about inheritance! This is something that really does come in very handy in a number of cases, and I can't imagine any way of doing it properly with just procedural tools. As I see it, this is the one thing that really sets OO design apart -- and to very good effect, because the only alternatives in a non-OO approach are not at all attractive.

3) Does anybody have any idea how perl 6's implementation of OO perl is going to be like? If so, is it going to be differnt from the current implementation?

So, you haven't internalized perl5's OO syntax yet (well, neither have I, really -- I still have to look up examples and man pages and Damian's beautiful OO book on those occasions when I want to make an OO module). And you're wondering if this stuff will be easier in perl6, so that maybe you should wait and not waste your time learning a soon-to-be-obsolete syntax...

Don't wait. Learn it now, with the syntax as it is. When perl6 comes out (I haven't heard anyone holding their breath...), it's design will be intended, in part, to implement all the functionality and concepts available in perl5, and then some; it will also be intended to provide a smooth and relatively painless transition out of perl5 syntax. So getting to know the OO landscape, even with the not-so-sporty vehicle of perl5, will be time well spent.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://291450]
[Discipulus]: problematic? i came back after just a week of course, I forgo teverything..

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2017-12-18 11:19 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (483 votes). Check out past polls.