http://www.perlmonks.org?node_id=291559


in reply to Re: perl OO - to use or not to use
in thread perl OO - to use or not to use

This may just be my take on the world, but I haven't yet found a non-trivial application that would be better written in procedural vs. OO. (OO vs. functional is an interesting debate, but I'm still trying to figure out where pure procedural is indicated.)

Now, I do tend to write a lot of scripts, like CGI scripts. The script itself is procedural, but it will use a lot of objects. Let's face it - a non-trivial web app is going to have a lot of similar functionality in each one of its scripts. The following is an incomplete list:

As such, those make sense to be put into objects. Some would say modules work just as well, but I always seem to run into the "Widgets are just like gizmos, except for ..." situation. Or, I do a lot of factoring, for which abstract base classes are eminently suited. So, I almost always start my designs with an OO flavor, tossing in functional and procedural as needed.

------
We are the carpenters and bricklayers of the Information Age.

The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Replies are listed 'Best First'.
Re: Re: Re: perl OO - to use or not to use
by leriksen (Curate) on Sep 16, 2003 at 00:53 UTC
    To some extent I agree with you - very few non-trivial applications are easier/better in procedural vs OO (and I agree with you on the functional approach too - but just try writting a useful Haskell version of a nontrivial app - sheesh!!). It just depends on how wide your values for non-trivial are :-)
    I find I use procedural approach heavily in the startup of an app development, and once that is humming, focus on the OO from then on. E.g. I usually focus procedurally during the startup of my app on
    • reading parameters (using Getopt::Long exclusively)
    • setting up logging (using Log::Log4perl exclusively)
    • setting up filehandles (using IO::File exclusively)
    • setting up timing/stats
    • when required, setting up DBI (using DBI)

    after that I start doing the decomposition dance
    oh, and btw, I make it a rule never to write the same code twice in an app - I always factor out to a sub or method. This help highlight new candidates for classes/modules faster. And if I notice that much of the code is avariation on a theme, I stop and try to find some abstraction that allows me to parametize that code.
    I think it was Donald Knuth who said
    Every problem in computer science can be solved with either more - or less - abstraction. Experience tells you which one of those to apply.