Today's entry, provided by Matthew Weier O'Phinney, is entitled Don't Reinvent the Wheel.
- Matthew Weier O'Phinney
- Matthew Weier O'Phinney is currently a PHP developer for Zend Technologies, and is lead developer for the Zend Framework MVC and server components. He has a number of open source contributions under his belt, and wishes he had more time in the day for raw coding.
- Richmond, Vermont
Developers are a strange breed; we all know that others have developed libraries and components that we can use, but we have an almost insatiable desire to do it ourselves. Some call it the NIH syndrome; others feel they can do it better, or simpler, or faster. We all succumb to it at one point or another as we mature as developers; I've heard the quote that the average PHP developer has developed 2.5 frameworks.
However, writing your own code all the time is a serious waste of your time. Why write yet another RSS feed parser, or another data table gateway, or another logger, or another mailer? The time you spend doing these things is time wasted; you can get more work done using somebody else's code, which ultimately means you can complete more projects and earn more money (or help a non-profit organization achieve its mission).
Additionally, a good developer repeats the mantra Don't Repeat Yourself to themselves constantly. While this typically means avoiding code duplication in your source tree, it can easily be extended to mean Don't Repeat Others. Don't go rewriting what others have already written for you.
Finally, with well-established projects, you benefit from having had many people review the code. This means that most design issues will have been resolved, often by people smarter than you (or by collective intelligence), and many, if not all, bugs will have been identified and fixed. It also means that the community will continue to fix problems, and you won't necessarily need to.
PHP has been around for a good many years now, and there are many places you can look to for quality code:
- The Standard PHP Library is a set of interfaces and classes that have hooks into the language and allow for a lot of sophisticated OOP usage. I've seen a number of people wanting to create Container or List classes; look no further than
ArrayObject, which allows you to create classes that can also look and feel like arrays, including letting you sort the items.
- The PHP Extension and Application Repository has rigorous requirements for accepting new components. Perhaps its greatest strength, however, is its collection and establishment of standards: how to document your code, requirements for testing code, and more. Components written for PEAR tend to be very high quality.
- The PHP Classes Repository offers little barrier for submission, but the user ratings allow you to filter and find those that other developers have found most useful or best implemented.
In addition to these, there are a number of competing component libraries and frameworks:
Many of these projects require their developers to unit test the code prior to release; for you, the end-user developer, this means you can be assured that the code will work as specified, and continue to do so in the future as new features and improvements are provided. This will in turn save you additional time, time not spent debugging when an upgrade is performed.
So, next time you need to add a feature to your site, consider searching to see if someone else has done so already. If you find someone who has, but the code doesn't live up to your standards or needs, instead of dismissing it and starting your own, try collaborating with the author. This way, others can benefit from your skills as well, and you don't pollute the Web with yet another solution to the same problem.