13.09.2016 Views

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Reusing Code<br />

537<br />

n<br />

n<br />

n<br />

n<br />

n<br />

n<br />

After you have a list of components, see which of them already exist. If a prewritten<br />

module has that functionality, consider using it. Don’t forget to look inside <strong>and</strong><br />

outside your organization for existing code. Particularly in the open source community,<br />

many preexisting code components are freely available for use. Decide<br />

what code you have to write from scratch <strong>and</strong> roughly how big that job is.<br />

Make decisions about process issues.This step is ignored too often in web projects.<br />

By process issues, we mean, for example, coding st<strong>and</strong>ards, directory structures,<br />

management of version control, development environment, documentation level<br />

<strong>and</strong> st<strong>and</strong>ards, <strong>and</strong> task allocations to team members.<br />

Build a prototype based on all the previous information. Show it to users. Iterate.<br />

Remember that, throughout this process, it is important <strong>and</strong> useful to separate<br />

content <strong>and</strong> logic in your application.We explain this idea in more detail shortly.<br />

Make any optimizations you think are necessary.<br />

As you go, test as thoroughly as you would with any software development project.<br />

Reusing Code<br />

Programmers often make the mistake of rewriting code that already exists.When you<br />

know what application components you need or—on a smaller scale—what functions<br />

you need, check what’s available before beginning development.<br />

One of the strengths of <strong>PHP</strong> as a language is its large built-in function library. Always<br />

check to see whether an existing function does what you are trying to do. Finding the<br />

one you want usually isn’t too hard. A good way to do this is to browse the manual by<br />

function group.<br />

Sometimes programmers rewrite functions accidentally because they haven’t looked<br />

in the manual to see whether an existing function supplies the functionality they need.<br />

Always keep the manual bookmarked.Take note, however, that the online manual is<br />

updated quite frequently.The annotated manual is a fantastic resource because it contains<br />

comments, suggestions, <strong>and</strong> sample code from other users that often answer the same<br />

questions you might have after reading the basic manual page. It often contains bug<br />

reports <strong>and</strong> workarounds before they are fixed or documented in the documentation<br />

body.<br />

You can reach the English language version at http://www.php.net/manual/en/.<br />

Some programmers who come from a different language background might be tempted<br />

to write wrapper functions to essentially rename <strong>PHP</strong>’s functions to match the language<br />

with which they are familiar.This practice is sometimes called syntactic sugar. It’s a bad<br />

idea; it makes your code harder for others to read <strong>and</strong> maintain. If you’re learning a new<br />

language, you should learn how to use it properly. In addition, adding a level of function<br />

call in this manner slows down your code. All things considered, you should avoid this<br />

approach.

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

Saved successfully!

Ooh no, something went wrong!