As web developers we are familiar with the DRY (Don’t Repeat Yourself) principle of programming. Cut & paste is the bane of object-oriented programmers, and we will frequently hear the phrase “Don’t reinvent the wheel”. However, I typically find myself and other colleagues in the world of PHP doing just that. The plethora of actively developed PHP Frameworks are a fluid testament to this fact. So are other libraries – sajax/xajax/projax for PHP Ajax work, jQuery/Dojo/Prototype/Mootools for JavaScript, and the list goes on.
Sure, there are unique qualities and features that separate third-party libraries, but the principle overlap is what – 75%? 80%? So why do we do it? The answer may be pride. Or, as someone so excellently put it this past weekend, our answer to “Don’t reinvent the wheel” becomes “Our wheels are rounder”.
The Democracy of open-source coding is an excellent catalyst for creativity. I wouldn’t be a programmer if it didn’t exist. But I believe there is a balance that must be struck between creativity, and the business requirements that keep us so gainfully employed. Here are several questions you may want to ask before clicking “New File” in your IDE:
1. What do you really need to accomplish?
For a recent work project, we needed a script to access a database at a set interval. Typically this would happen via a cron job, but I thought I could do better. Instead, I created a series of classes based on Solar_Php that could queue and execute batch processes in the background. I thought this was the rounder wheel – not having to babysit a cron process. While the overall benefit of this approach is yet to be determined, I do know that there was another way, one that involved less code — and less time.
2. Does something already exist that will handle your requirements?
In the world of Content Management where I exist, there are many prebuilt solutions. Joomla!, WordPress (used here of course!), and Drupal are the first that come to mind. Also, for features like comments, there are IntenseDebate, Echo, and DISQUS. These are regularly vetted for stability and security, and could save you hours of time.
3. What is the impact on the larger project ecosystem?
This last question cannot be overstated. You have to know the system requirements for any third party plugins or libraries that you install. And you need to know how they will perform on your server. For shared hosting, remember that memory is usually low, in the 16-32 MB range. Also think of Disk I/O and network traffic involved.
Hopefully, these thoughts will help you to better plot out that new addition to your site or application, and save you some precious time. Remember, time = money!
Happy coding, etc.