Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Right job for the tool.

by GrandFather (Saint)
on May 30, 2014 at 01:47 UTC ( [id://1087913]=note: print w/replies, xml ) Need Help??


in reply to Right job for the tool.

I use light weight OO (mostly just for encapsulation) in almost every significant script (say 100 lines or more) I write. I consider it a cleaner alternative to using a bunch of global variables or passing a bunch of state around as parameters.

After a while you tend to build up a code tool kit. If that is OO based it's easier to wrangle into a new shape for specific applications and you get more mileage from the toolkit.

Perl is the programming world's equivalent of English

Replies are listed 'Best First'.
Re^2: Right job for the tool.
by ForgotPasswordAgain (Priest) on May 31, 2014 at 10:29 UTC

    I have a little mental model of scripters (as opposed to module writers. I script more than write modules). The amount of OO we use as a function of experience is something like a bell curve.

    Start with simple procedural scripts, with global variables to be able to tweak things. Eventually use subroutines to organize the code a bit. Use subroutines for things that are repeated. Pass parameters to those subroutines to control their behavior. You're climbing the curve!

    Keep adding parameters for things you didn't realize you needed (or changing requirements), till you have 6-, 7-, ..., 10-parameter subroutines. The requirements change so much that you try to generalize things, usually overly and/or incorrectly. Pass some parameters through the command-line, because it gets tedious changing the code. Eventually, after you tried several homemade systems of command-line parsing, you invent some "App" module. This is where you've discovered OO. You realize other people probably did this before, so you look for a module to take care of command-line parsing and passing around that one object with all your app state. You might go through several of those modules. Eventually you're trying MooseX::Getopt or whatever and create the most unmaintainable, abstract code possible. You've neared the peak of the bell curve and begun a nervous breakdown.

    A year or two of your life passes, which you can't recall, but you can't believe you used to write code like that. You're on the downside of the curve, the path to recovery and wisdom. You realize (or have to believe for your sanity) nobody could ever have cleanly maintained this stuff anyway, so you avoid OO, you avoid frameworks. You're convinced that it makes business sense anyway. You write 1000-line stream of thought one-off code with no illusion of "organization" or "logic", since that doesn't exist in your world. You spit the phrase "project owner". While reviewing others' code you might advise avoiding using globals or give tips about how to make the code clearer by.... oh, what's the use: deep inside you know it doesn't matter. You've lived the horror. You'll live in a log cabin soon. Logs are real objects. Squirrels don't have business needs.

    :P

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-16 18:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found