lazy saunter

(personal learnings in computation)

Tuesday, December 28, 2010

configuration file for perl applications

In maintaining lots of "legacy" perl applications, I am constantly encountering hard-coded values for items like email addresses, database parameters, and those that change depending on if the app is running in testing or production mode. In order to test one such app, a programmer had to go into about 30 files and comment out a line or two of code. When putting it back into production mode, the programmer had to do the reverse and uncomment those lines in the 30 files.

An easy solution is to isolate the variables whose values often change in a "configuration file". Every other file in the application points to this file and has access to its variables. Thus, a "testing" variable can be set to "1" when the app is being tested or to "0" when the app is in production (or some such variation). In this way, the 30 files that change depending on test/prod mode can simply check the value of the "testing" variable and execute different bits of code depending on which value is being stored in the configuration file. Moving from test to prod, or vice-versa, means only changing one file.

Not only is this much quicker, it is much less prone to error. While setting up the project to use the configuration file takes a little extra time, the amount of time saved in maintenance down the road pays for it pretty quickly.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home