Specifications

If you end up developing your own functions or components, you should seriously consider
making them available to the PHP community when you have finished. This is the principle
that keeps the PHP developer community such a helpful, active, and knowledgeable group.
Writing Maintainable Code
The issue of maintainability is often overlooked in Web applications, particularly because we
often write them in a hurry. Getting started on the code, and getting it finished quickly some-
times seems more important than planning it first. However, a little time invested up front can
save you a lot of time further down the road when youre ready to build the next iteration of an
application.
Coding Standards
Most large IT organizations have coding standardsguidelines to the house style for choos-
ing file and variable names, guidelines for commenting code, guidelines for indenting code,
and so on.
Because of the document paradigm often previously applied to Web development, coding stan-
dards have sometimes been overlooked in this area. If you are coding on your own or in a
small team, its easy to underestimate the importance of coding standards. Dont do it because
your team and project might grow. Then you will not only end up with a mess on your hands,
but also a bunch of programmers who cant make heads or tails of any of the existing code.
Naming Conventions
The goals of defining a naming convention are
To make the code easy to read. If you define variables and function names sensibly, you
should be able to virtually read code as you would an English sentence, or at least
pseudocode.
To make identifier names easy to remember. If your identifiers are consistently format-
ted, it will be easier to remember what you called a particular variable or function.
Variable names should describe the data they contain. If you are storing somebodys surname,
call it $surname. You need to find a balance between length and readability. For example, stor-
ing the name in $n will make it easy to type, but the code will be difficult to understand.
Storing the name in $surname_of_the_current_user is more informative, but its a lot to type
(easier to make a typing error) and doesnt really add that much.
You need to make a decision on capitalization. Variable names are case sensitive in PHP, as
weve mentioned before. You need to decide whether your variable names will be all lower-
case, all uppercase, or a mix, for example, capitalizing the first letters of words. We tend to use
all lowercase, as its the easiest thing to remember.
Using PHP and MySQL for Large Projects
C
HAPTER 22
22
USING PHP AND
MYSQL FOR
LARGE
PROJECTS
463
28 7842 CH22 3/6/01 3:37 PM Page 463