13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

538 Chapter 25 Using <strong>PHP</strong> <strong>and</strong> <strong>MySQL</strong> for Large Projects<br />

If you find that the functionality you require is not in the main <strong>PHP</strong> library, you have<br />

two choices. If you need something relatively simple, you can choose to write your own<br />

function or object. However, if you’re looking at building a fairly complex piece of functionality—such<br />

as a shopping cart, web email system, or web forums—you should not be<br />

surprised to find that somebody else has probably already built it. One of the strengths of<br />

working in the open source community is that code for application components such as<br />

these is often freely available. If you find a component similar to the one you want to<br />

build, even if it isn’t exactly right, you can look at the source code as a starting point for<br />

modification or for building your own.<br />

If you end up developing your own functions or components, you should seriously<br />

consider making them available to the <strong>PHP</strong> community after you have finished.This<br />

principle keeps the <strong>PHP</strong> developer community such a helpful, active, <strong>and</strong> knowledgeable<br />

group.<br />

Writing Maintainable Code<br />

The issue of maintainability is often overlooked in web applications, particularly because<br />

programmers often write them in a hurry. Getting started on the code <strong>and</strong> getting it finished<br />

quickly sometimes seem more important than planning it first. However, a little<br />

time invested up front can save you a lot of time further down the road when you’re<br />

ready to build the next iteration of an application.<br />

Coding St<strong>and</strong>ards<br />

Most large IT organizations have coding st<strong>and</strong>ards—guidelines to the house style for<br />

choosing file <strong>and</strong> variable names, guidelines for commenting code, guidelines for indenting<br />

code, <strong>and</strong> so on.<br />

Because of the document paradigm often previously applied to web development,<br />

coding st<strong>and</strong>ards have sometimes been overlooked in this area. If you are coding on your<br />

own or in a small team, you can easily underestimate the importance of coding st<strong>and</strong>ards.<br />

Don’t overlook such st<strong>and</strong>ards because your team <strong>and</strong> project might grow.Then<br />

you will end up not only with a mess on your h<strong>and</strong>s, but also a bunch of programmers<br />

who can’t make heads or tails of any of the existing code.<br />

Defining Naming Conventions<br />

The goals of defining a naming convention are<br />

n To make the code easy to read. If you define variables <strong>and</strong> function names sensibly,<br />

you should be able to virtually read code as you would an English sentence, or at<br />

least pseudocode.<br />

n To make identifier names easy to remember. If your identifiers are consistently<br />

formatted, remembering what you called a particular variable or function will be<br />

easier.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!