Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by Cody Pendant (Prior)
on Jun 16, 2003 at 01:09 UTC ( [id://266092]=note: print w/replies, xml ) Need Help??


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

I recently had to update some website code which accessed a certain directory to get flat files. I needed to change to a different directory. That directory location was hard-coded into three different scripts.

It only took me a minute or two to update and save all three files, but as it was a web application, a minute or two could have meant quite a few errors because of the discrepancy between what script A was reading and what script B was reading.

Only a small thing, but I was forcefully reminded that if I wanted to do a cutover like that from one file system to another, it would get done much more cleanly if the directory location could be changed in only one file, so I put it into a shared "require" file ASAP.



“Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer.”
M-J D
  • Comment on Re: When Is Dividing Code Into Different Subroutines/Packages Important?

Replies are listed 'Best First'.
Re: Re: When Is Dividing Code Into Different Subroutines/Packages Important?
by yosefm (Friar) on Jun 16, 2003 at 19:00 UTC
    Let's go even further: Never hard-code anything, except when it's:
    • A constant at the top of you'r script, so it's easy to find
    • or, better yet, in a different file shared by all scripts in your app, if you have more than one.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (8)
As of 2024-04-23 22:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found