Specifications

type, they consume a lot of screen space on many peoples monitors. We use an indent level of
two to three spaces for all projects.
The way you lay out your curly braces is also an issue. The two most common schemes are as
follows:
Scheme 1:
if (condition) {
// do something
}
Scheme 2:
if (condition)
{
// do something else
}
Which one you use is up to you. The scheme you choose should (again) be used consistently
throughout a project to avoid confusion.
Breaking Up Code
Giant monolithic code is awful. Some people will have one huge script that does everything in
one main line of code. It is far better to break up the code into functions and/or classes and put
related items into include files. You can, for example, put all your database-related functions in
a file called dbfunctions.php.
Reasons for breaking up your code into sensible chunks include the following:
It makes your code easier to read and understand.
It makes your code more reusable and minimizes redundancy. For example, with the pre-
vious
dbfunctions.php file, you could reuse it in every script in which you need to con-
nect to your database. If you need to change the way this works, you have to change it in
only one place.
It facilitates teamwork. If the code is broken into components, you can then assign
responsibility for the components to team members. It also means that you can avoid the
situation in which one programmer is waiting for another to finish working on
GiantScript.php so that she can go ahead with her own work.
At the start of a project, you should spend some time thinking about how you are going to
break up a project into planned components. This requires drawing lines between areas of
functionality, but dont get bogged down in this as it might change after you get going on a
project. You will also need to decide which components need to be built first, which compo-
nents depend on other components, and the time line for developing all of them.
Building Practical PHP and MySQL Projects
P
ART V
466
28 7842 CH22 3/6/01 3:37 PM Page 466