Tuesday, December 11, 2007

Ready, Willing, and Able

After seeing the site I mentioned ye, Function A Day, got me thinking of something.

You often hear experienced PHP programmers say that there is a mentality among PHP coders to only use a small subset of PHP's capabilities. I know this is true from my personal experience where I have written a functionality I needed, small or large, and later found that there already was something very similar implemented as an extension that came bundled with PHP.

The reason this happens is that we are not always aware of all the possibilities that PHP offers. In fact, I find it amusing that some programmers are puzzled by this; often contributing it to inexperience and outright sloppiness. While I do not doubt that is often the case , I do doubt that it is the principle reason though. The simple fact is that there is just too many darn functions in PHP to keep track of and more are added all the time. Most of the time it is actually easier to just write the piece of code you need than to browse Google and the PHP manual looking for a specific functionality. I would even argue that it is a weakness in PHP that there are so many functions.

Another good reason not to always rely on PHP's functions is that they may have annoying defects or they simply do not behave the way you want them to. The final reason to code things for yourself is just to keep yourself writing code. With an abundance readily available functions and classes, with out-of-the-box solutions, it is easy to get lazy and rely too heavily on them. This damages a programmer's own skill to write basic things from scratch. Personally I find it helpful to understand the underlying principles of a PHP function before I use it and the best way for me to do that is to write the function myself.

In my mind, the solution to this problem is to use PHP's wide array of functionality but not obsessively. Remember to rely on your own skill and imagination when solving problems. If there is a quick fix in the form of a PHP function, by all means use it. It is faster and more efficient but do not spend an hour pouring through the manual when you could have written your own solution in just ten minutes.

No comments: