Wednesday, February 22, 2006

Why I Like PHP

I am happy to see that Tim Bray has a few nice things to say about PHP, and is giving the language some respect.

Although I program for the web in my day job with Java and JSP on a Websphere Application Server, I have been using PHP for my personal web sites for several years now, and wouldn't think of using J2EE for these. My personal view of J2EE is that it has much more overhead than necessary for most small web projects. If you need to put together a simple REST-style web service, PHP allows you to do it in a simple, straightforward manner. Using J2EE for such tasks strikes me as akin to using an elephant gun to shoot mice. PHP has proven to be plenty adequate for me to manage my sites and to work with Amazon.com's web services. I believe it would also do an adequate job on most of what I am currently doing for my employer with the J2EE (assuming I designed a workable XML schema for the mountains of data we use.)

I have a sign hanging over my desk that I printed from Sean McGrath's Blog back in 1973. It reads as follows:


"Some software complexity cannot be destroyed,
it can only be moved from one place to another."

"Recognizing this type of complexity is a key
skill in SW engineering in my opinion. Those
who cannot spot it are themselves easily
spotted. They are the ones swimming in layer
upon layer of interface/class/factory/aspect
as they struggle to get the ab initio
complexity to disappear in a puff of
refactoring logic."

I don't know what Sean was specifically thinking about when he wrote that, but I do know that the J2EE immediately came to my mind when I read it. I believe that a lot of complex problems are easier to solve with simple tools than with overly complex ones.

Sure, it's easy to write spaghetti code with PHP. But, it's easy to get very sloppy with HTML also. In fact, that's what allowed HTML to dominate the internet; it's very easy to use and it is very forgiving if you get sloppy. But that doesn't mean that you have to be sloppy in your programming. Those who choose to use good programming techniques can write some very elegant programs in PHP if they wish to do so.

It's a little like capitalism, where everyone is free to fail, or to succeed at whatever they want to do. While capitalism is sometimes messy, and allows people to be sloppy if they want to and still have some success, the really big rewards go to those who choose not to be sloppy. The big winners are those who choose to be well organized and bring self-discipline to their chosen work: people like Bill Gates, Paul Graham, Henry Ford, Sam Walton, Thomas Edison, Nikola Tesla, Dennis Ritchie.

In addition to its specialized design as a web scripting tool, I believe the biggest reason for PHP's success is that it is probably one of the easiest, and least expensive ways for anyone to get into web programming. It is widely available on low-cost web hosting providers, is easy to learn, and there is very low overhead. As a bonus, old C programmers, like myself, are very comfortable with it.

Like many things in life, success is not determined by the tools you use, although good tools are very nice to have, and certainly make life easier. The most important ingredient is the amount of commitment and self-discipline one is willing to bring to bear on the path one chooses to follow. You can write sloppy code with PHP and never improve. Or, you can learn to write some very elegant code and keep improving.

PHP started out as a simple library of tools developed by Rasmus Lerdorf in support of his personal web site. It has gradually improved over time, and along with the improvements came a worldwide following. One of the more recent improvements is a fairly good implementation of the W3C DOM2 in PHP version 5. Like C, I think that PHP allows you to do many things in a straightforward manner. Also like C, I find that PHP doesn't get in your way or bog you down.

0 Comments:

Post a Comment