Glue Interactive

The Difference Between Good Code and a Good App

This post dropped Jan 10th, 00:50, in to Web Development

Over the past few days I've been armpit deep in the source files of Wordpress, one of the worlds most popular and customized pieces of blogging software. I've been reading documentation, examining the database & navigating my way through the many PHP files of Wordpress - the end goal being a plugin which interfaces with Pligg, a popular open-source social media (read "Digg-style") piece of software.

Considering that Wordpress is 4 years old, has a half dozen full-time developers and has many high profile users, I was expecting to find some quality code underneath it all.  When I did lift the hood, I was astonished as to what I found...

$wpdb->query("UPDATE $wpdb->users SET user_activation_key = '$key' WHERE user_login = '$user_login'");
$message = __('Someone has asked to reset the password for the following site and username.') . "\r\n\r\n";
$message .= get_option('siteurl') . "\r\n\r\n";
$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
$message .= __('To reset your password visit the following address, otherwise just ignore this email and nothing will happen.') . "\r\n\r\n";
$message .= get_option('siteurl') . "/wp-login.php?action=rp&key=$key\r\n";

if (FALSE == wp_mail($user_email, sprintf(__('[%s] Password Reset'), get_option('blogname')), $message)) {
    die('<p>' . __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...') . '</p>');
} else {
    wp_redirect('wp-login.php?checkemail=confirm');
    exit();
}

For you non-programmers out there, that piece of code processes a request to reset the password of a user's account. Any programmer who has more than a couple years experience knows the code is doing many things wrong: namely raw SQL and HTML email code interwoven with PHP. Now I understand that Wordpress was written from scratch, and forked from a codebase that was originally written before the MVC architecture was common practice, but come on! That code is horrible!

Yet the worst part, aside from all the bad syntax and complete disregard for an coding best-practices is the lack of any kind of code comments or documentation. Anywhere. I'd guess that maybe 10% of any of the functions in Wordpress have any sort of comments above them and probably only 5% of those shed any real light on what the function does. It's only been through my long history tinkering with PHP applications and liberal use of the grep utility that I've been able to make heads of tails about how Wordpress functions internally.

To be quite honest, Wordpress is probably in the bottom 10% of quality in terms of software source code that I've ever seen.

This begs the question, "If it sucks so much, why is it so popular?"

Well, it's because Wordpress does its public-facing things incredibly well. Themes, plugins, ease on install, UI, community, etc are all created in (I hate to say) beatufil and elegant ways.  From initial install to creating your first blog post, the process for the end user is spot on.  And thanks in simple easy to read code and great documentation, creating themes and plugins is simple and painless.

This is a prime example of why success in writing and selling software is contingent on the quality of the user experience, and not the quality of the code behind the user experience.  Like Microsoft, Wordpress figured out that in order to have successful software, you don't need to write the best source code.  Instead, you need to create the best and easiest customer experience. This is why Linux is hands down better software than anything Redmond will ever write, but it's still looking for that mainstream acceptance.  The end user's experience using Linux is still a few generations behind the ease of use of Windows.

It's as if a car owner likes their car based solely on the fact that the interior looks nice and the car is easy to drive.  Never mind the fact that the car could be powered by an engine from a 1930s lawnmower.  As long as the user has a good experience, and the technology powering it "just works," they could care less to look under the hood. Which to me sounds idiotic.  Even though you'll never have to deal with it, don't you want the best quality engine under your hood?  I would.

The reason software can get away with a quality user experience, but crappy engine, is that as consumers go, 99.9% of them wouldn't know the difference between quality professional source code and something like Wordpress.  It's not that they can't look under the hood - they can. They just don't know how to make heads or tails of the code once they do.

Unlike nearly every other kind of technlogy and engineering in the world, programming is all virtual.  You can't feel software to see if it feels heavy or "well built."  You can't examine the source code to see if it looks worn or needs replacing since, well, software never wears down.  Once "it works," it works.

My point in all of this is why you should care.  If the source code works, won't age or break down and my experience as an end-user is great, why do I care that the underlying code is awful?  Because it makes moving in any direction from where you are that much harder.

Crappy code make it harder for the Wordpress team to develop and maintain the code base.  Crappy code means less care is taken by developers to be effecient, making scaling for high-volume webistes harder.  Crappy code makes it harder to upgrade to new versions of Wordpress.  But most importantly, crappy code makes understanding and preventing security holes by the development team very hard.  A problem that has bitten Wordpress in the butt a few times before.

All in all, for moest people the things in the above paragraph won't matter.  They'll install their blog on their web hosting and blog for 6-months and then get busy with other things.  But if you're looking to use some open source software like Wordpress for your next website, consider looking beyond the user-facing functionality and see what lies beneath the hood.

Post Details

Published
Jan 10th, 00:50
Category
Web Development
Author
Jeff