The story behind this book is personal. A few years ago, I came to the realization that what I had done in my professional life until then was not quite up to my own expectations. Though not dramatic enough to qualify as a midlife crisis, this realization got me thinking in new ways.
I was doing web programming in PHP at the time. I was in an isolated position in the company I was working for, so I decided to put my own work under the microscope. I asked myself, “How can I boost myself to a higher level of performance?” One idea that occurred to me was to review my own work at the end of every day. What did I do that was most successful? How could I do more of that? What was less successful? How could I do less of that?
The task that stood out like a sore thumb was debugging. It was obviously taking up a major part of my time, and anything that would make debugging more efficient or diminish the need for it should make me more productive. I looked around for ways to catch bugs earlier. I tried defensive programming, with limited success. Then I stumbled across agile processes and test-driven development, Extreme Programming, and refactoring. It seemed like what my colleagues and I had been doing for some years, only better. I took up the methodology first in my own, individual work. At this point, there was little recognition of it in the PHP community. I was early; I worked test-first with the very first alpha version of PHPUnit that appeared in March 2002.
The idea of writing this book occurred to me when I inherited some nasty PHP code from a fellow programmer. I realized that the code could be improved, refactored, in ways that I could describe systematically. This had to be useful to someone, I thought. And there was no book about agile processes and test-driven development in PHP.
Then, one event jump-started the project: I got fired from my job. (A few months later, I became a member of the board at the company I had been fired from, but that’s an entirely different story.) It took about three years to finish the book. It was hard to get it into a shape that the reviewers were sufficiently enthusiastic about, and I had to rewrite most of it a couple of times. Marcus Baker and Chris Shiflett came into the process near the end. In the meantime, the marriage of PHP, agility, design patterns, and unit testing had become a mainstream subject. The most important official events in this process were the release of PHP 5 and the start of the Zend Framework project.
Among the many things I learned along the way is the importance of reading books yourself if you want to write one. I believe in the importance of deep understanding, not as knowing a lot of details, but as knowing each detail in depth. And I believe that comes from having a strong foundation and from being able to see one issue from several perspectives.
That has led me to repeatedly reexamine the basics. I keep asking seemingly stupid questions; in fact, I'm often mistaken for a beginner in web forums, even when discussing subjects I know well. And I believe that the deeper my own understanding is, the better I can explain the subject to others. I hope this quest will prove helpful to you too.