Although I form very strong opinions regarding software development as I learn lessons from experience, I also endeavor to keep an open mind and be willing to even change my mind sometimes, especially if the thing I have formed an opinion about changes. I blogged about an example of this in How I Learned to Stop Worrying and Love Java's Ternary Operator. Several observations have led me to think that I need to look closer at PHP again and that perhaps my opinion of PHP may improve. In this post, I look at these interrelated observations that have led me to decide to give PHP another look.

Prevalence

PHP has become a highly prevalent programming language on the web. PHP Usage Stats indicate a general upward trend in PHP usage. On the current TIOBE Programming Community Index (April 2011), PHP is the fifth-most popular programming language. I see .php in URLs all over the place. Both anecdotal and more objective evidence indicates that PHP has become a widely popular language. Knowing the basics of PHP and having some PHP experience cannot help but make a developer's skills more generally applicable and add a meaningful tool to the developer's tool set.

Rounding Out the Top Five

As I mentioned above, PHP is the fifth most popular language on the Tiobe Programming Community Index. It happens to be the only one of the top five that I have never used in any significant way. I've used the first four (listed in order they appear on the index: Java, C, C++, and C#) significantly more than PHP. I've worked quite a bit with Java, C++, and C, and have worked enough with C# to feel comfortable with it, but I have not put similar effort into using or learning PHP because of my initial adverse response to it.

I think that many of us who dabbled a bit with PHP years ago have been left with a stubborn impression that PHP is for hackers. In Holub on Patterns, Allen Holub wrote, "A determined individual can write garbage code in any language." I have found this to be true in any programming language that I have used in any significant way, but it seemed pervasive in PHP code even without needing to spend much time in that environment. I have reason to believe that things may have been improved or may be improving in PHP.

I had already decided to try PHP out again, but was even more motivated to do so after reading Why PHP was a Ghetto. Post author Kenny Katzgrau writes about "why the non-PHP development world generally has such disdain for PHP and the community surrounding it." His list of reasons all apply, but I also think he nails the main reason when he writes, "PHP code bases tend to be hacky and unmaintainable." None of this was a surprise to me because it certainly has been the opinion of just about every non-PHP developer I have known, but I was also encouraged to read this:

PHP was a ghetto. But the development of frameworks like Zend and CodeIgniter have greatly pushed the language development into the right direction. ... The fact is, a PHP applications can be as well-written as an application in any other language, and probably have the additional advantage of speed. The widespread use of MVC-style development in the PHP world is a relatively recent phenomena though, and admittedly, we can probably thank Rails for it.

Because Katzgrau seems to understand the source of disdain for PHP in the past, I'm hoping that his positive assessment of where it is today and the direction it is moving is correct. It sure sounds promising!

One of the reasons I like to learn new languages every once in a while is to adopt practices from those languages in my coding and to better "think outside of the box." I have to admit that I have not previously been interested in learning any PHP because I didn't want to learn any of that or be tainted by any of those practices. I'm less fearful now of the negative influence of immersing myself in this language now.

Practicality

In the previously mentioned blog post Why PHP Was a Ghetto, post author Kenny Katzgrau wrote, "I’m no PHP fanboy — in fact, I’m very language-agnostic. I write PHP more often because, you guessed it, people pay me to." In the end, my renewed interest in PHP comes down to my believing that it offers the most obvious practical advantages at this point in time. Had I not gotten into Groovy, I probably would have dived into Python as my next major language, but Groovy is fulfilling my outside-of-the-web-browser scripting needs nicely. I also have significant interest in Scala and Clojure, but I think there are more practical advantages to learning PHP better at this point.

In many ways this is analogous to human languages. Although there may be many appealing features to languages such as Italian, French, Japanese and so forth, I feel that learning Spanish is the most practical "second language" for those of us who are primarily English speakers living in the western United States. There is little question that Spanish is the most common spoken and written language encountered on a daily basis in the western United States after English. Even if I was attracted to languages other than Spanish, the most practical move would be to improve my Spanish vocabulary and speaking and listening skills. It's the language that I'd have the most opportunity to use and take advantage of on a regular basis. For me, PHP is like this in the computer programming world. I already know several widely prevalent programming languages in Java, C, and C++, but PHP is an obvious "major language" that I am likely to run into repeatedly in the future.

PHP's Fit

PHP is obviously known as web scripting language. The PHP FAQ states, "PHP is an HTML-embedded scripting language." Although PHP does now offer command line scripting support, I'm not interested in it for that. I have a difficult time imagining where I'd use PHP for command line scripting over Groovy, Python, or even Perl. In fact, I'd probably use shell scripting before I'd use PHP command line scripting. It's definitely on the web that PHP offers its greatest potential and benefit.

NetBeans PHP Support

A minor factor influencing my decision to start learning PHP in earnest is the availability of PHP code support in NetBeans 7.0 (available in previous versions as well). I use NetBeans frequently for my Java and Groovy development, so it is nice to continue using a tool I'm comfortable with to work with PHP. Although there is a "PHP only" download option for NetBeans, I already use the "All" version that includes PHP.

Conclusion

Despite a general disdain toward PHP from most of we non-PHP developers, it is obvious that PHP has been wildly successful in the web browser space. I still don't know if I'll learn to love or even like PHP, but I want to believe. I certainly think I can benefit from a certain level of comfort with such a prevalent language. I also believe that basic familiarity with PHP can open up new software development opportunities. Learning Groovy has provided me with several practical advantages that I use on a near daily basis, but some of the new languages I have learned before have offered less concrete advantages for regular use. I'm hoping learning PHP will provide me the types of benefits that learning Groovy provided. I doubt that I'll ever use PHP as much as I use Java/Groovy, but I do look forward to learning more about a language that is largely new to me.

15 comments:

From my very limited experience reading PHP blogs in recent days, I have definitely been left with the impression that there is more overlap and associated tension (comparisons/contrasts/flame wars) between PHP and Ruby on Rails than there is between PHP and Java. This makes some sense because PHP and Rails are largely aimed at the same web-only crowd whereas Java has a much broader purview. A good example of this is the recent post Confessions of a Converted PHP Developer: Ugly Code. I have seen the positive influence of Ruby on Rails and Ruby on Java, but it appears to me that the effect of Ruby on Rails may have been even greater on PHP. Indeed, the effects of Ruby on Rails are likely as much to credit for the improvement of PHP development practices as anything else.

I share the same impression of PHP. I think its popular because small learning curve. I wrote my first web app in PHP for this reason. But in retrospect, it really is a great way to write slow difficult to maintain software for a very small team. Groovy really is great though and I'd pick Groovy/Grails over PHP easily today.

I used to hate Java for the exact opposite reason you hated PHP back 10 years ago. I found Java too academic, too restrictive, a steep learning curve, not only slow in development but also buggy and slow in execution (at least the first few JVM's). I hated the verbosity of the language, the lack of community support and so on. But that was a long time ago and I feel different about Java today for various reasons.

I did however stick with PHP, writing multiple commercially successful web applications and in general I can say that I am really glad I did.

You also mentioned Python. About a year ago I also started working with Python since I needed to develop some non web based applications and even there one can sometimes pick up the "hackiness" one tend to get in PHP scripts. But bloody hell, it is a super productive language and productivity is a measure I take above everything else. I am now an official Python addict.

I'm definitely hoping for a more positive experience with PHP this time as I give it more of a chance. I think improvements in PHP along with my own willingness to find things to like in different languages and my experience with dynamic languages Groovy and Ruby may help me "appreciate" PHP more now.

Thanks for the comment. I've read many good things about the Zend framework. I won't really be able to appreciate it until I've learned a little more about PHP, but I appreciate the recommendation and plan to look at it further when I can better understand what it offers.

I see you found my "ugly php" rant on LeesWeblog. I just went back to read it again, and I still stand behind what I wrote...which is amazing, to me.

The landscape of PHP developers is changing. There is still a wealth of crap-code out there, but it's getting better. I employ and work with 6 people who use PHP for some really big problems...and we do it well! This isn't something I think I could have said about the PHP-centric-industry in general, even 3 years ago.

Thanks for providing that feedback. Although I generally have felt that the PHP community has improved significantly, I at the same time realized that I am an outsider to PHP. It is nice to hear from folks who are more familiar with the PHP community.