I just had a talk about WordPress with a colleague so I thought I should finally publish this draft I wrote a few months ago...

Being a lucky full time Ruby on Rails developer for more than a year, I've got used to readable code and a clear separation of concerns.

Nonetheless, I recently had to customize a WordPress installation. Installing the software was a breeze and the administrative interface looks reasonably good and comes with all the bells and whistles one may expect at this point in time. WordPress being an extremely successful and popular open source project, I actually had some hope about the code being somehow structured to offer a proper level of customization.

I had never been so wrong.

Let's play to find out the extent of the disaster: will you spot where in the world is the actual code that retrieves the content for the list shown in the Manage posts screen? Hint: in the version I was working with, the function is called without any parameters.

Yes, it's that bad. It seems we've got all the cons of PHP focused in one, massively deployed, application. Do I really need to line up the usual suspects?

  • Global variables everywhere. Globals even seem to be part of the whole design.
  • SQL queries everywhere. Same queries performed at multiple places.
  • Extremely poor object-oriented design. Somebody please buy those guys a copy of PoEAA.
  • Lots of serialized "stuff" in the database (btw, what are those cached RSS feed objects doing in the table which stores the application settings? WTF!)
  • No view helpers of any kind, let's build those dropdowns the hard way every time
  • Coding conventions strictly follow PHP's own no conventions methodology. The wp_ prefix seems to be used erratically through out the code.
  • Some functions libraries contain more lines of code than fully functional Rails applications of average complexity.
  • Strictly no automated testing.
  • Criminal use of syntax such as mixed style if statements (C-like Vs Python-like), omission of curly braces, non-semantic indentation, ...
  • And of course, the whole thing is SQL embedded in PHP embedded in HTML embedded in PHP embedded in ...

I know it's possible to write clean, object-oriented and well designed PHP applications but let's face it, we are not even talking about 5% of the global code base deployed worldwide.

WordPress certainly doesn't represent the State of The Art in term of PHP code but if you care about your platform, the last thing you will ever want is a flagship product or killer app with a code that looks so bad. WordPress is definitely not an exception, just take a peek under the hood of some of the most popular PHP apps...

This excruciating experience has led me to think that PHP as we know it must die. It's been helpful but its learning curve has been steadily acting against its very own community. We've all been rookies but what's the future of a platform for which 95% of the code consists of large balls of sticky spaghetti? When I see such an amount of crap in such a popular open source application I actually wonder how anyone can go down the slippery road leading to code rot for such a long time. I see two possible answers: utter stupidity or freshman's naiveness. We've all been there and I for one knows that newbies usually have plenty of time to write plenty of code they will be ashamed to look at a couple of years later if they eventually turn into grown up software craftsmen.

Call me an *sshole but the code zealot I am fully agrees with the crystal clear elitist stance of DHH when it comes to building tools and frameworks.

The only hope for PHP is to break up with its legacy, Zend should start to think about something else. They already missed the ubiquitous web framework era so why don't they focus on something completely new? Why not dreaming about a major overhaul of the language with a magnitude similar to Python 3000?