|Keep It Simple, Stupid
Re: Object Oriented Orientationby dwm042 (Priest)
|on Aug 01, 2011 at 19:28 UTC
Comments, suggestions? Do ya'll use OO Perl a lot?
I probably use OO Perl far less than many of the far better programmers who have replied, and my opinion is that of a sys admin who generally is asked to write fast and dirty scripts to Just Get Things Done.
For small programs, under 100-200 lines or so, I see no advantage to writing in OO. Using OO? Plenty of advantage, because how else do I get my programs to be under 100 lines? Perl's brevity is in part due to the extensive CPAN library programmers can use.
The moment you start thinking about code you would like to stick around, code you would like to keep and reuse, code you would like to share, the advantages of OO come to the fore. IMO, it takes more work to write OO, but the final product has a better defined interface, is better isolated (that word encapsulation raises its head), is easier to hand over to a beginner and have it "just work".
It's better, in the long run, to have a 2,000 line object in a module that gets turned into a 30 line main program than 1,500-1,800 lines of functional chicken scratch. People might "get" the point reading the 30 line main program. People (including you) will forget the details in your 1,000 line+ bit of chicken scratch. You'll also forget that 2,000 line module too, but you have a better chance of going, "Hey, I sort of remember what I did here.."
When I first started into Perl OO, I wrote an object that encapsulated a closure that gave me a date iterator. It was just practice, until 2 months later it became a crucial part of a production program. So even dabbling in OO will give you a bit of a toolkit you can put to practical use later.