Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Perl Module Useage

by dga (Hermit)
on Apr 10, 2003 at 16:12 UTC ( #249656=note: print w/replies, xml ) Need Help??

in reply to Perl Module Useage

I have 2 general rules of thumb.

First: If I need to use a bit of code in more than 1 place, I take that time, instead of a cut/paste, to make it into a sub and change the existing bit of code to call the sub and the new bit of code becomes a call to the same sub.

There are times when the sub needs to be made a bit more generalized and I handle this at that time also.

Second: If I want to use that sub in another script I build that sub into a module which I can then import the function.

At the same time, if it makes sense I try to make the sub into an OO type of interface so I don't need to import the functions into my scripts unless it really makes sense to do it that way.

My experience is that if this overhead is done when there is only 1 existing piece of code which requires changing to use the new interface (sub {} or use Module;) then it is quick and easy to have these nice interfaces so that next time I want this functionality I just type use Module; my $thing=Module->new(...);, or use Module qw( my_keen_sub );

This has a really low cost in the short term and a huge win in the medium to long term, especially if I add a bit of pod to the sub and then a bit more when it gets into a module.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2021-06-18 06:36 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (88 votes). Check out past polls.