473,657 Members | 2,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

excessive use of include files

Is there anything wrong with using a lot of include files?

On one part of my website, I have a form. The page it posts data to,
includes a different file based on some of the values. The include
files also include other pages based on different values. All of
these work together to select the right information from the database
and display it in the correct format.

I'm just wondering if it is better to put all the code in one file
rather than in the include files.

Thanks,

-Tom
Jul 17 '05 #1
9 2313
On 16 Sep 2004 11:31:45 -0700, st******@yahoo. com (Tom Cat) wrote:
Is there anything wrong with using a lot of include files?

On one part of my website, I have a form. The page it posts data to,
includes a different file based on some of the values. The include
files also include other pages based on different values. All of
these work together to select the right information from the database
and display it in the correct format.

I'm just wondering if it is better to put all the code in one file
rather than in the include files.


There is an argument that pulling the include files together takes
time, but if you include library files that contain hundreds of
functions, it ends up causing the same kind of issue.

In one of my larger projects (a content management system) I ended up
programatically deciding which includes to process, based on what was
required for the page... you have to design that kind of system into
your code from the beginning though.

Just my two penneth :)
Jonathan Beckett (jo********@plu ggedout.com)
working on : http://www.pluggedout.com/penpals
Jul 17 '05 #2
st******@yahoo. com (Tom Cat) wrote in message
news:<fa******* *************** ****@posting.go ogle.com>...

Is there anything wrong with using a lot of include files?


Performance-wise, no, if the server is equipped with a PHP accelerator,
and yes, if it isn't. Opening a file takes time, but PHP accelerators
take care of the problem by compiling scripts and caching the executable
code.

Style-wise, it depends... If each include file has a good reason to
be separate from the rest (for example, if it contains a group of
functions/classes implementing a distinct functionality) and has been
thoroughly tested prior to including into the application, there's
nothing wrong with using a large number of includes.

Cheers,
NC
Jul 17 '05 #3
> I'm just wondering if it is better to put all the code in one file
rather than in the include files.


How would you like to maintain big function or class libraries in single files?
Jul 17 '05 #4
If you have 200 include files containing one function each then it will take
longer to load that one include file containing all 200 functions. I
personally group similar functions into the same include file, but have each
database table class in its own file. At runtime I only load the files that
I know I will need. I can also have different versions of functions in
different files, so I can load include.xml.php 4.inc or include.xml.php 5.inc
depending on which version of PHP I am running.

It takes a little up-front organisation, but I think it's worth it.

--
Tony Marston

http://www.tonymarston.net

"Tom Cat" <st******@yahoo .com> wrote in message
news:fa******** *************** ***@posting.goo gle.com...
Is there anything wrong with using a lot of include files?

On one part of my website, I have a form. The page it posts data to,
includes a different file based on some of the values. The include
files also include other pages based on different values. All of
these work together to select the right information from the database
and display it in the correct format.

I'm just wondering if it is better to put all the code in one file
rather than in the include files.

Thanks,

-Tom

Jul 17 '05 #5
Tom Cat <st******@yahoo .com> wrote or quoted:
Is there anything wrong with using a lot of include files?


Too many include files is bad - but the much more common sin is not
splitting things up enough.
--
__________
|im |yler http://timtyler.org/ ti*@tt1lock.org Remove lock to reply.
Jul 17 '05 #6
On Fri, 17 Sep 2004 09:50:56 GMT, Tim Tyler <ti*@tt1lock.or g> wrote:
Tom Cat <st******@yahoo .com> wrote or quoted:
Is there anything wrong with using a lot of include files?


Too many include files is bad - but the much more common sin is not
splitting things up enough.


I agree.

I tend to have one include each for...

Session Functions
- always the first include, doing things like starting the session,
processing cookies and so on...

Database Functions
- generic things like opening and closing a connection

HTML Functions
- any functions that return HTML - with the aim being to not have
HTML in the scripts that are executed.
.... and following on from there, a number of includes to do specific
stuff.

Jonathan Beckett (jo********@plu ggedout.com)
working on : http://www.pluggedout.com/penpals
Jul 17 '05 #7
Tony Marston wrote:
I
personally group similar functions into the same include file, but have
each database table class in its own file. At runtime I only load the
files that I know I will need.


I tend to structure my include files by task the task they are trying to
acheive rather than by what they do (with a few exceptions).

I tend to use include files in two different ways:

1) include files in the same directory as the host script, which are
typically only included by one or two host scripts: the idea here is to
make the operation of the host script apparent while minimizing the amount
of code the developer has to read.

2) library include files: these are usually outside the document root and
don't change very often.

That doesn't really answer the question, so to address it less indirectly
what are the issues with using includes:

1) someone has already mentioned the issue of the overhead of loading lots
of different files although this wouldn't be top of my list of concerns.

2) seperation of code maturity and layering of functionality should
facilitate the development process.

3) never use relative paths to shared include files (unless its '.' see
above) - its a bit of maintainence issue.

4) about the only problem I have with PHP is that you can get in a mess with
global symbols - e.g. suppose you have a library include which does
authentication. This is used by several different scripts. Developer A
decides that it would be a good idea to add a function 'log_ip()' to his
script. Some time later developer B thinks she needs the same function but
decides to put it in the library. Her scripts all work well with the change
but she doesn't know to test developer A's code which is now broken.
This is solved in other languages by using namespaces or offline linking.

5) Pear advises to put each class definition in its own file. I did consider
this rather wasteful until I came across the __autoload function (OK so you
still don't need to keep each class in its own file but it does make things
a lot simpler). Also phpXref gets a bit confused if you don't do this.

6) Pear also recommends where to include files from. I still take issue with
this, but it is important to adopt a strategy and to stick to it so you and
PHP can find your way around your code. I try to ensure that code in any
file only invokes classes/functions declared in the same file or in a file
which it explicitly includes.

7) most of the time when I say include I really mean 'require_once'

HTH

C.
Jul 17 '05 #8
st******@yahoo. com (Tom Cat) wrote in message news:<fa******* *************** ****@posting.go ogle.com>...
Is there anything wrong with using a lot of include files?

On one part of my website, I have a form. The page it posts data to,
includes a different file based on some of the values. The include
files also include other pages based on different values. All of
these work together to select the right information from the database
and display it in the correct format.

I'm just wondering if it is better to put all the code in one file
rather than in the include files.

Thanks,

-Tom


Thanks everyone for the answers. After reading them I think I'm ok.

-Tom
Jul 17 '05 #9
"Tom Cat" <st******@yahoo .com> wrote in message
news:fa******** *************** ***@posting.goo gle.com...
st******@yahoo. com (Tom Cat) wrote in message

news:<fa******* *************** ****@posting.go ogle.com>...
Is there anything wrong with using a lot of include files?

On one part of my website, I have a form. The page it posts data to,
includes a different file based on some of the values. The include
files also include other pages based on different values. All of
these work together to select the right information from the database
and display it in the correct format.

I'm just wondering if it is better to put all the code in one file
rather than in the include files.

Thanks,

-Tom


Thanks everyone for the answers. After reading them I think I'm ok.


Actually, no. What you're doing is using include files in lieu of functions,
which is a rather crummy way to program in PHP.
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3284
by: Chad Scharf | last post by:
I have a legacy ASP application running on IIS 6.0 (Windows Server 2003 Web Edition) that is throwing an error when processesing a certain asp page that has about 200 or so include directives. We've checked the spelling, paths, include directives, and files individually and all of them work. We have also commented out random ones (4 or so at a time) and then the page works. It doesn't matter which ones we comment out, just so long as...
0
6117
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug file as folows. I need help to resolve them ASAP: cl /c /nologo /MDd /W3 /Od /GR /GM /Zi /GX /D "_DEBUG" /D " WIN32" /D "_W INDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /D "_USRDLL" /
5
2506
by: David Mathog | last post by:
One thing that can make porting C code from one platform to another miserable is #include. In particular, the need to either place the path to an included file within the #include statement or to very carefully define the order in which paths are searched with command line options on the compiler. Both can cause problems, especially when dealing with complex software distributions. It occurs ot me that by extending the C include...
1
7475
by: Minh | last post by:
I've just installed VS.NET 2003 on my Athlon XP 1800+. However I couldn't get any project with STL includes to compile even if I create a new empty project (and added #include <string>). It gave me a bunch of "missing ;" errors. I did reinstall the whole thing a few times but it didn't work. Anyone have any idea? Thanks c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xutility(862) :
1
4563
by: ya man | last post by:
when i use #include <iostream.h> in some files i get lots of error messages of the kind 'ambiguous symbol this is solved when i use #include <iostream why is that ? and can i use #include <iostream.h> in some way examples to the error messages c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\streamb.h(90): error C2872: 'ios' : ambiguous symbo c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\streamb.h(90): error C2872:...
2
3012
by: Brian Kitt | last post by:
I have a process where I do some minimal reformating on a TAB delimited document to prepare for DTS load. This process has been running fine, but I recently made a change. I have a Full Text index on one column, and punctuation in the column was causing some problems down the line. This column is used only for full text indexing, and otherwise ignored. I decided to use the following regular expression to remove all punctuation (actually...
16
2375
by: Chris Shearer Cooper | last post by:
In our Visual Studio 2005 application, we have several of our application's H files that are #included into stdafx.h. What is odd, is that when we change those application H files, VS2005 doesn't trigger a rebuild of the entire app (or of anything, for that matter). Is this a setting somewhere? Thanks!
3
1819
by: scotp | last post by:
Does anyone know what would cause excessive page faults running the js function below? The most common browser used is IE 6. The page has records that include text & checkbox inputs. Each record also has a hidden input named "questions", whose value is an id that is used in the name of inputs to be disabled. The number of page faults increases dramatically as records increase. I know it is the for loop that is taking the extra time,...
7
1471
by: Dennis Yurichev | last post by:
Hello. I'm looking for any algorithm which can take C++ experssion at input and offer at output the same expression with excessive bracketts removed. Where should I look for it?
0
8326
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8845
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8743
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8622
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5647
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.