
• Build a prototype, based on all the previous information. Show it to users. Iterate.
• Remember that, in all of this, it is important and useful to separate content and logic in
your application. We’ll explain this idea in more detail in a minute.
• Make any optimizations you think are necessary.
• As you go, test, as thoroughly as you would with any software development project.
Reusing Code
Programmers often make the mistake of rewriting code that already exists. When you know
what application components you need, or on a smaller scale, what functions you need, check
what’s available before beginning development.
Sometimes programmers rewrite functions accidentally because they haven’t looked in the
manual to see if an existing function supplies the functionality they need. Always keep the
manual bookmarked if you are online, or download the current version and browse it locally.
Take note, however, that the online manual gets updated quite frequently, and you also have the
advantage of being able to browse the annotated manual. The annotated manual is a fantastic
resource as it contains comments, suggestions, and sample code from other users that often
answers the same questions you might have after reading the basic manual page. You can reach
it at
http://www.php.net/manual/
Some programmers who come from a different language background might be tempted to
write wrapper functions to essentially rename PHP’s functions to match the language with
which they are familiar. This practice is sometimes called “syntactic sugar.” It’s a bad idea—it
will make your code harder for others to read and maintain. If you’re learning a new language,
you should learn how to use it properly. In addition, adding a level of function call in this man-
ner will slow down your code. All things considered, this is an approach that should be
avoided.
If you find that the functionality you require is not in the main PHP library, you have two
choices. If you need something pretty simple, you can choose to write your own function or
object. However, if you’re looking at building a fairly complex piece of functionality—such as a
shopping cart, Web email system, or Web forums—you won’t be surprised to find that these
probably have already been built by somebody else. One of the strengths of working in the Open
Source community is that code for application components such as these is often freely available.
If you find a component similar to the one you want to build, even if it isn’t exactly right, you
can look at the source code as a starting point for modification or for building your own.
Building Practical PHP and MySQL Projects
P
ART V
462
28 7842 CH22 3/6/01 3:37 PM Page 462
Kommentare zu diesen Handbüchern