in reply to One Big Script v. Several Small Scripts

My first significant Perl script was a CGI database manager. Because it was my first script, I did a lot of things that, in the light of more experience, seem dead wrong. One of those things was combining too many functions (i.e. query handlers) into one large program. It started innocently enough. I just wanted to be able to make a query, do a search, and present the results. Then came the stats. Heck, I can compute the stats in the same program. After all, the data access engine is already there. After that came an addition to format the stats in a nice downloadable pdf. Might as well just stick that in there, too! And did I mention how convenient having all that stuff in one big script made it to use global variables? Well, you get the idea.

As far as compile-time goes, frankly I don't care whether it's 10 milliseconds or two seconds. It's not one of those 10,000 hits-per-day sites. What I do care about is maintainability, and the capacity to modify function by building out rather than up. This could have been achieved by having one module whose only job was to interface to the database via exported data objects and methods. That way each query could have been handled by a different, much shorter script, and the data retrieved and contained in nice, tidy object variables instead of being splattered across a score or two of global scalars. Plus -- and most importantly of all -- I could follow the logic of each query handler without having to scroll back and forth through several thousand lines of code.

Now I know. And I'm sorely tempted to do a major rewrite, except -- doggone it all -- the blasted thing works!

  • Comment on Re: One Big Script v. Several Small Scripts