CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Which is better, one big script or multiple small scripts?

 



DrZed
User

Jun 29, 2000, 6:49 PM

Post #1 of 4 (571 views)
Which is better, one big script or multiple small scripts? Can't Post

I'm writing a forum script and I'm not sure if it would be better to have one single script that processes all of the commands, or if each function should get it's own script.

My thoughts are that, as one big script, it's loading a lot more than it needs to with each call.

However, I'm thinking that servers probably cache frequently loaded programs, so one big program might actually be quicker than lot of little scripts.

Basically, I'm not sure which is better. Any suggestions?

Dr. Zed


rGeoffrey
User / Moderator

Jun 29, 2000, 10:41 PM

Post #2 of 4 (571 views)
Re: Which is better, one big script or multiple small scripts? [In reply to] Can't Post

My big project started with one script that was called for everything. It then determined what to do, 'required' the appropriate files to get some subroutines, and did stuff.

The problem I ran into was that the special cases started to get out of hand after about a year and it was a pain to continue to evolve the project.

The new model is to have dozens of very small scripts that 'use' the correct combination of modules and verify that it was sent the right data, then make a call to one of the modules.

One other change I made was to split the doing of stuff from the display of stuff.
For example if you want to delete something from a page, you call edit.pl which will make the changes. But edit.pl has no knowledge of how to display the page. After it has done its business it prints "Location:display.pl\n\n" and ends.

Then display.pl takes over and prints the page to the browser. A nice side effect of this is that if the user tries to reload the page, then they are reloading the display, not the edit, so there is less chance of corrupting the data and it does what they expect it to.


mckhendry
Deleted

Jun 30, 2000, 7:08 AM

Post #3 of 4 (571 views)
Re: Which is better, one big script or multiple small scripts? [In reply to] Can't Post

I would suggest having one big script that is nothing but subroutines. That's what I am doing right now with a billing program. For each command a different subroutine is executed, so my main program consists of a call to a subroutine to print the header block, an if/elsif/else statement that calls a subroutine based on which command to perform, and a call to a subroutine to print the footer block. That way all the pages have the same look and feel. I don't know how much this relates to what you're doing Zed, but I definitely think subroutines are the way to go. Good luck with it.


dws
Deleted

Jun 30, 2000, 8:53 AM

Post #4 of 4 (571 views)
Re: Which is better, one big script or multiple small scripts? [In reply to] Can't Post

I suggest that you consider ease of programming and maintanence before you worry about performance. Having everying in one big script can make programming a major hassle. Consider the problems you'll have if you need to pick a single large script up to extend it after not having looked at the code for a couple of months.

Partition your code in some way that makes sense, and at least keep the significant partitionings (packages, groups of packages, or related subroutines) in separate files. With everything in one large file, it takes a lot of discipline to prevent entropy from taking over. With separate files, you can at least keep things like HTML rendering confined to one place.


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives