Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: When Is Dividing Code Into Different Subroutines/Packages Important?

by meredith (Friar)
on Jun 14, 2003 at 03:32 UTC ( [id://265852]=note: print w/replies, xml ) Need Help??


in reply to When Is Dividing Code Into Different Subroutines/Packages Important?

I use packages and break out into subs for two major reasons: maintainability and reuse.

That way, I can break out items that I use often, as you have done with PassMaster, and have a single place to fix bugs. Imagine if you had used PassMaster instead as simply a cut and paste snippet, and put it in some 12 scripts. Then, later along, you realize that the masking becomes ineffective if the user sends a certain excape sequence! Sure, fixing 12 scripts can be done, but we're lazy, aren't we? Yes.

I also tend to start my projects by starting a bit on each major component, and put things into packages as I go. That way, if I realize that I've already written something, all I have to do is use it. Boy am I making things easy for myself ;)

When done right, using subs and packages also makes it easy to expand your code, or refactor it (to an extent). If you haven't noticed the real point yet, it's all about making things easier on you. It's just a little effort for a big payoff.

P.S.: I don't believe you need the brackets in the DataBase Interface section -- the package statement applies until the next package or end of file. diagnostics should probably left out when the code goes to production, too. :)

Update: Oh also, ++ for the question! I expect some great responses coming soon!

mhoward - at - hattmoward.org
  • Comment on Re: When Is Dividing Code Into Different Subroutines/Packages Important?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-04-25 10:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found