I’ve finally cracked, I can take it no more. I’m just going to have to blog about it.
Before I quit the world and disappeared sailing for 4 months this summer, I wrote a post titled “Drupal is shit“, in it a ranted about how I couldn’t stand Drupal, and that I use either Wordpress or an MVC framework in its place. That post drew quite a bit of attention this summer after Webschuur blogged a reply to my original post.
The time has now come for me to bitch about the very product I defended in that post; Wordpress.
Here, are you ready for it, I’m going to say it. Wordpress is shit!
Ok, it’s not on the face of things, I happen to love Wordpress, but I’ve been working on a contract rececntly which involves some fairly in depth Wordpress development. I’ve had to peer under its skirt and what I’ve found was not something you’d want to tell your friends about.
This post goes beyond my opinion of Wordpress though, I want it to highlight a more fundamental problem with PHP development. People just don’t seem to be very good at it, and it’s giving PHP a bad name.
I got a bit of a telling off in the Drupal thread for not giving examples of what I considered to be poor code, so I’m not going to allow that to happen again. Let’s take a look at a random snippet of Wordpress code.
Can anybody tell me what that does? I doubt it, and that makes for bad code from the off. Thankfully, despite the atrocious function naming and cringe inducing syntax, it is doc tagged, so a mouse over in eclipse tell me that the_post() “iterates the post index in the loop”. I’m still not entirely sure what’s going on here, but I’ve got a better idea.
Let’s dig a bit deeper, F3 in Eclipse open the declaration.
/**
* Iterate the post index in the loop.
*
* @see WP_Query::the_post()
* @since 1.5.0
* @uses $wp_query
*/
function the_post() {
global $wp_query;
$wp_query->the_post();
}
This hasn’t helped much, I still have no idea what’s going on, but it has invoked a sub rant about Globals.
Why do people use them? It’s such a dumb idea. You have no control over that variable, no idea where it comes from, and no idea who has fettled with it before it’s used in this function.
Now, at this point, I’d open declaration on the the_post() method, but I can’t since Eclipse has no idea what $wp_query is. I can’t even find it without a search through the code because Wordpress doesn’t do, is put classes in individual files. They are just mixed up where ever in an orgy of mouldy spaghetti code. Again, this is bad because it makes a developers life hard for no benefit.
Searching for “WP_Query” was of little benefit since it’s littered throughout the code. I had to try another tactic, let’s find the function itself with a search for “n the_post”.
Aha, found it in wp-includes/query.php which isn’t too bad I suppose, although I would have preferred the file be called the same as the class within it. wp_query.php. Makes it nice and obvious then doesn’t it.
Opening the file shows another horror story; a huge mix of procedural and OO code. I can understand why this may have happened, it was probably because they are trying to port it to OO yet retain backwards compatibility, at least I hope that was the reason, but this is just a bloody confusing mess.
Anyway, onward we go. Let’s open up the code for the_post() and see what’s going on.
/**
* Sets up the current post.
*
* Retrieves the next post, sets up the post, sets the 'in the loop'
* property to true.
*
* @since 1.5.0
* @access public
* @uses $post
* @uses do_action() Calls 'loop_start' if loop has just started
*/
function the_post() {
global $post;
$this->in_the_loop = true;
$post = $this->next_post();
setup_postdata($post);
if ( $this->current_post == 0 ) // loop has just started
do_action(’loop_start’);
}
I think this can be summarised with a simple, yet effective WTF!!!!???!!!
I don’t think I can bear to dig any deeper. What is wrong with using an iterator? There are well established design patterns for this sort of thing.
The bottom line is, Wordpress is like so many projects out there, a complete kludge of crap code. I will still defend Wordpress for being a good product, I can make it do things quickly (mostly) and for standard use it’s nice and easy to use, but my god do I pity you if you have to go beyond that.
HTML is also well and truly mixed in with the core code, which means to apply a specific design, you may well have to start hacking around within the functions of a plugin. This means that what should be a modular website with themes, quickly turns into a customised hunk of code that you can’t upgrade any more through fear of braking it all.
The above example reflects the vast majority of PHP code I’ve worked with, and it’s sadly a rare thing to stumble across well written and designed PHP software. The unshakable attachment to it’s roots as a hobiest language are all too apparent.
Come on folks, we can do better than this. When you turn up for work tomorrow, have a think about replacing those globals in your code with a static class or two, but more importantly, find out why you should. The PHP world will thank you for it, I promise.
3 comments so far...
Yeah I agree, Drupal is better.
Wordpress is the bain of my existence! Calling it a piece of shit is an insult to pieces of shit! I even bought “Wordpress for dummies” and that too is a horror. My site? Yeah, I have to use it. Everything financial involved with it my company pays for, so I’m stuck. Computer Geek? Yes I am, but on the graphics side of things. Coding? My brain doesn’t work the way it needs to to understand coding, in fact, coding makes my brain bleed. Even so, my site looks and functions pretty good, but only after months of head scratching and cussing.
NOW, I’ve been roped into doing a similar site for my son’s guitar instructor (in exchange for guitar lessons). Here I am back at square one with a new blog site to build. Of course this instructor wants all sorts of shit I don’t know how to do and here I am again trying to make heads or tails out of WordPress For Dummies. . . I absolutely HATE WordPress!
I completely agree with you!
I can’t understand how wordpress is so popular. Don’t get me wrong, Wordpress by itself is a great blogging platform. At the moment I’m working on a wordpress site for a customer (who’s previous webmaster abandonned the project) and I feel like It’s been years I’ve performed so poor. Wordpress is lacking the base priciples of good programming (like separation of concerns and solid OOP for instance) or I’m missing something.
leave a reply