Home arrow PHP arrow Debugging and Performance

Debugging and Performance

Debugging is an important part of coding. One way to make the debugging process easier is to write quality code to begin with. This article, the first of two parts, will point out some of the most common coding errors, and help you identify problems in your code. It is excerpted from chapter 12 of Zend PHP Certification, written by George Schlossnagle et al (Sams; ISBN: 0672327090).

TABLE OF CONTENTS:
  1. Debugging and Performance
  2. Flattening if Statements
  3. Splitting Single Commands Across Multiple Lines
  4. One Equal, Two Equals, Three Equals
  5. Testing for Resource Allocation
By: Sams Publishing
Rating: starstarstarstarstar / 9
November 22, 2006

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
Chapter 12: Debugging and Performance

Making mistakes is human, and so is fixing them. In your day-to-day programming adventures, it's inevitable to introduce bugs in your PHP code, especially when you're writing very complex applications with tens of thousands of lines of code spread across tens of files.

When you're prototyping an application, being able to avoid common programming mistakes is important to ensure that your code will be well-written from the very start. In this chapter, we'll provide you with some guidelines on writing efficient code, debugging faulty scripts, and identifying bottlenecks when performance becomes an issue for both you and your clients.

Terms You'll Need to Understand
  • Bug

  • Coding standard

  • Code readability

  • Comparison operators

  • Performance

  • Caching

  • Portability

Techniques You'll Need to Master
  • Writing readable code

  • Proper commenting

  • Comparing heterogeneous data

  • Debugging

  • Identifying and preventing performance bottlenecks

  • Preventing performance issues

  • Improving database performance

  • Using content and bytecode caching

Coding Standards

Writing your code in a structured manner is, perhaps, the smartest decision you can make. Although there aren't any predefined coding standards that everyone in the programming community recognizes as better than the rest, deciding from the very beginning on a set of conventions will go a long way toward helping you make fewer mistakes.

Documenting your code is particularly important. To make this job—probably at the top of the Ten Most Hated Tasks of programmers worldwide—a bit easier, you can even use one of the many automated tools available on the market, such as PHPDocumentor, which can extract documentation directly from your code if you structure your comments in a particular way.

Regardless of how you introduce them in your applications, good comments and documentation will make sharing your code with other members of your team easier, as well as make sure that you'll remember what it does when you get back from that three-week vacation. Remember, preventing bugs is much better than hunting for them.

Extra whitespace and empty lines, although unimportant as far as the functionality of your code is concerned, can be an extremely valuable tool for writing better code:

if ($foo == 'bar') 
{
$i = 0;
/**
* foreach loop, get the content out of it
*/
foreach ( .... ) 
{
}
}

By separating your code into logical groups, your source will be cleaner and easier to read. Also, indenting each line according to the code block it belongs to helps you figure out immediately what the structure of your script is.



 
 
>>> More PHP Articles          >>> More By Sams Publishing
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: