Debugging

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian W. Kernighan

No matter how good a programmer you are, you will at some point find that there are at least one or two errors in your code - sometimes because you hit the wrong key while typing, other times because you misunderstood how a function worked, and sometimes even because you were coding at 5am.

While Nixon's law states "the man who can smile when things go wrong has thought of someone he can blame it on", most programmers need something more solid than blaming other people, and this is where learning the art of debugging comes in.

The process of removing programming errors, commonly referred to as "bugs", from your code can be a long and drawn out process if you do not bring the right tools to bear, and can sometimes even then be hard work. Tracking down bugs is something you will improve at over time, like anything else - to begin with, it is important to fully understand the arsenal you have at your disposal.

This chapter will cover the various ways you can find and solve errors, but also ways you can handle errors that are outside of your reach.

 

Want to learn PHP 7?

Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: What is a bug? >>

Previous chapter: Cross-platform code 5

Jump to:

 

Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.