Help - Search - Member List - Calendar
Full Version: Organizing Code
WorkTheWeb Forums > Web Hosting Help > PHP Help
Support our Sponsors!
noe0729
I am in the process of reorganizing my code for a program I am writing. One of the things I am doing is removing functions from individual files, putting them in their own files and calling them with the include statement. Since the entire program runs from one main file would it be smart to have all my functions included first thing in that file or just put the include statements where the functions are needed throughout all the files?

None of functions are very large (no more than 10-30 lines each).

Any thoughts/ideas?
ralford
Modularity is the way to go. I would keep the functions all in one file. Then include this file on any page where a function is needed. This way, the functions only need to be written once.

Whenever you feel like you've written code before, or if you see two things that are similar, there is usually a way to turn it into a single module or function.

Hope this helps!
noe0729
QUOTE(ralford @ Mar 3 2005, 07:30 AM)
Modularity is the way to go.  I would keep the functions all in one file.  Then include this file on any page where a function is needed.  This way, the functions only need to be written once.

Whenever you feel like you've written code before, or if you see two things that are similar, there is usually a way to turn it into a single module or function.

Hope this helps!
*


I understand the concept of modularity which is why I am reorganizing. I am looking to minimize the amount of includes I have to make to functions by including them all at the very beginning of the main file that calls everything else. I was wondering if it is smarter to do that or just include the functions as I need them in the individual files.
mraberration
QUOTE(noe0729 @ Mar 3 2005, 08:34 AM)
I understand the concept of modularity which is why I am reorganizing.  I am looking to minimize the amount of includes I have to make to functions by including them all at the very beginning of the main file that calls everything else.  I was wondering if it is smarter to do that or just include the functions as I need them in the individual files.
*




Its better to have more include files the including 100% of your code in every file. Think about modularity in function.. If you have user functions put them in a user_function.inc.php file and so on... This will scale better.
noe0729
QUOTE(mraberration @ Mar 3 2005, 11:05 AM)
Its better to have more include files the including 100% of your code in every file. Think about modularity in function.. If you have user functions put them in a user_function.inc.php file and so on... This will scale better.
*



Cool. I will just include the functions when I need them instead of at the start of my script. Thanks!

PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.