November 10, 2006

On PHP and Maintainability

Posted at November 10, 2006 09:43 AM in LinkBlog , PHP .

Why is PHP Code Considered Hard To Maintain

Why is PHP code considered hard to maintain? Is it the language that produces code that is hard to maintain, or is it that the popular ambassadors of the language happen to be programs that are hard to maintain?

I too have spent lots of time pondering this question. If you look at PHP from a language feature point of view, it is up there in ranks with Java and C++. It has classes, public, protected, and private variables and methods, abstract classes, static methods, inheritance, interfaces, built-in iterators, magic class methods, and loads of other goodies that you won't find in the base distribution of other languages. (I'm not saying everything is there, but the necessary prerequisites definitely are.) The general consensus is that object-oriented code is easy to maintain and it is definitely possible to produce object-oriented code in PHP. However, few PHP applications (at least the ones in the free/open source sphere) are object oriented. I tend to blame the shallow learning curve for the language. It is very easy for somebody to pick up PHP and learn the basic features. Many people learn PHP as a first web programming language because of this. These people are either a) too young to have been exposed to good object-oriented programming practice or b) are naive of PHP's advanced features that support maintainability (probably because they aren't prevalent and advertised enough).

It is as good a time as any to point out that any language can be "abused" by the implementor. I have seen some bad Java programs, but you don't hear people saying Java is hard to maintain. The reason is there are many Java success stories in enterprise. Do people write off PHP as a poor programming language because they lack knowledge of successful and maintainable PHP applications? Whose responsibility is it to share how successful PHP can be when properly implemented?

It is an interesting blog entry, and I recommend you read it if you have concerns about the maintainability of PHP.

Trackback

You can ping this entry by using http://blog.case.edu/gps10/mt-tb.cgi/11059 .

Comments

If you look at PHP from a language feature point of view, it is up there in ranks with Java and C++.

Ranks "up there?" When I think of a language heavy in "features," Java and C++ do not come to mind. I guess it depends on what you define as a "feature" of a language.

you won't find in the base distribution of other languages

I think that might be where the problem starts. With PHP, everything is wrapped in the "base distribution."

The general consensus is that object-oriented code is easy to maintain

"4 of out 5 Computer Scientists recommend daily use of object orientation to improve maintainability."</tongue location="cheek">

There is nothing inherent in object oriented code that makes it easier to maintain.

It's just as easy to write bad OOP as it is to write bad FP, AOP, etc.

you don't hear people saying Java is hard to maintain

I'll say it. Java is hard to maintain (if programmed by a bad programmer).

there are many Java success stories in enterprise

Sun's (and Oracle's and IBM's) marketing machine at work. You don't have many empassioned engineers writing blog entries about how Java "saved their project." You do get a lot of whitepapers generated from places like the Burton Groups of the world doing that. (Related note: http://troutgirl.com/blog/index.php?/archives/22_Friendster_goes_PHP.html)

It's never technology that produces bad code. It's people. That being said, there are a lot of things in PHP's base distribution that gives rise to some concerns.

Posted by Jeremy Smith at November 10, 2006 01:11 PM

Wha happened to my comment?

Posted by Jeremy Smith at November 14, 2006 02:51 PM

I was just purging all the spam comments in my blog. I think your comment might have been collateral damage.

Posted by Gregory Szorc at November 14, 2006 03:13 PM

I used my magical powers to restore the comment.

Posted by Gregory Szorc at November 14, 2006 03:43 PM

Oh the spam...

I just did a cursory check of how many IPs are being blocked in the blog's .htaccess file -- 31778.

Posted by Jeremy Smith at November 14, 2006 08:36 PM

And it still isn't good enough. Any way we can get a CAPTCHA plugin installed?

Posted by Gregory Szorc at November 14, 2006 08:42 PM

I hate CAPTCHAs.

From my eyeball-analysis of the logs, the IP banning has done a really good job (80% spam reduction). But it is still not enough. Again from my eyeball analysis, forced preview before posting a comment should take care of another 80% or more (depending on how quickly they adapt).

The problem implementing forced preview is that I will need to go through all of the blogs, parse each blog's "individual entry archive" looking for the comment posting form (not too hard), and modify it. Sounds like a Blog v2.0 thing to me.

Which would obviously leave the question, "when is 2.0 coming?" I've no idea. Probably soon after you're using GMail to check your Case mail.

Posted by Jeremy Smith at November 15, 2006 11:30 AM

I just don't have much to say these days, but so it goes. Today was a total loss. I guess it doesn't bother me.

Posted by Sten6171 at January 9, 2007 12:58 AM

Post a comment










Remember personal info?