Archive for May 2005

WordPress code quality

WordPress logo WordPress calls itself a “state-of-the-art semantic personal publishing platform” — but the engine that lies beneath this shiny, smooth-looking CSS-styled surface is not that nice.

I find the coding standard in the current (version 1.5.1.1) code to be below what I would expect from a piece of software as popular as WordPress:

  • Global variables are used all over the place! Global variables should be used sparsely, if at all, for they often make the code more difficult to understand. Other people agree that Global Variables are Bad.

    From looking through the code I’ve found a $wpdb variable which is used as a global handle to the database. That’s fair enough — such a handle is needed, and lots of different pieces of the code need access to it. But still it could be handled better if one consistently used $GLOBALS['wpdb'] instead of global $wpdb followed by a later use of just $wpdb — by using the $GLOBALS array one precisely describes that this variable is just that: global.

    There are also lots of other global variables in the code, and they are often used in a much more subtle way than the $wpdb variable. A simple count of the (unique) variables declared global in the wp-includes directory gives no less than 108 variables!

  • Lack of comments! The core files such as functions.php contains tons of functions, but no comments. Take a random function like mysql2date() with a signature of

    function mysql2date($dateformatstring, $mysqlstring, $translate = true)

    is hard to understand without reading the code. The source has no doc comments which describe the arguments or the result type.

    The online documentation website, the Codex, is still very incomplete when it comes to information about the internals, and I would much prefer to have the documentation right there where it’s needed: in the code.

  • Duplicated code! Why does the code in post.php not use the wp_insert_post() function declared in functions-post.php? Instead it seems to duplicate the logic in wp_insert_post(), something which will sooner or later lead to problems.

  • Incredibly long lines! It is clear that there has been made no attempt to break the code into lines at a reasonable site (that is, less than 80 characters per line).

    Those long lines makes the code annoying to read unless I make my terminal or Emacs huge and it makes diffs cryptic when one has to compare two 200 character lines to figure out a change. For someone who would like to look into the code those things make a real difference and should not be neglected because it is “just cosmetics”.

  • Mixed XHTML and PHP code. The themes in WordPress use no page template system what so ever, they just output the raw XHTML to the user — making it easy to create invalid XHTML output.

    To defend this choice, then I must say that I’ve never been impressed by template systems like Smarty which claims to separate the application code from the presentation. To do this they give you a template language in which you can program your pages — if you look more closely at it, then this template language ends up being simply a reimplementation of the original language. So instead of if ($foo || $bar) ... you write {if $foo or $bar} .... Has this bought you anything, except requiring you to learn another language with its possible quirks and limitations?

    If that was what the WordPress developers asked themselves, then I can understand why they simply went with normal PHP code mixed with XHTML. But it can be done better than that: PhpWiki uses a cool system where all the XHTML code is generated using a set of classes and functions. Using such a high-level interface automatically makes the produced XHTML code compliant and it makes the source so much cleaner. With some proper caching the performance shouldn’t be affected, but the long term quality of WordPress would improve.

I hope that the WordPress developers take steps to fix and improve some of the things I’ve described above. Apparently, there are others who agree with me about the quality of the WordPress code. Despite my complains, I’ll keep using it, for even though I can find lots of things to complain about, I still think it’s the best software for what it does.

In the beginning was the Command Line

In the continued effort to cleanup my site I uploaded the Gospel of Tux yesterday. Another text which I had a copy of at my old site is the essay “In the Beginning was the Command Line” by Neal Stephenson.

Since my copy was just a direct copy I’ve decided that there isn’t much point in me putting it up again. A much more interesting read is this commentary by Garrett Birkel.

Eurovision Song Contest, 2005

Denmark in 2nd place Stéphanie and I were watching the yearly Eurovision Song Contest yesterday, and it was a lot of fun! And let me just reveal here at the beginning that Denmark didn’t win… and neither did Switzerland… but Denmark lost to Switzerland! Grrr! :-)

At the beginning things looked really well for Denmark. Our song was quite nice and we quickly rose almost to the top of the charts. And we were ahead of Switzerland, even though they followed us closely.

Switzerland leads! But then something went wrong and suddenly Switzerland was leading the competition, to Stéphanie’s huge enjoyment! Their “Cool Vibes” song by the Vanilla Ninjas was okay, even though the text was a bit strange, containing a chorus with the text “Why did you kill me?”. I think the idea was that someone beyond the grave would talk back to some murderer?

A little later Switzerland have to leave the first place, and Denmark came ahead of Switzerland again. The score remained like that with Denmark being 5-10 points ahead of Switzerland, but then at the very end Switzerland got the maximum 12 points and jumped ahead of Denmark! (Stéphanie was jumping too… :-)

Helena Paparizou, Greece But in the end it didn’t matter — Greece won the contest with a song by Helena Paparizou. In old Greek mythologi Helena was supposed to be the most beautiful woman in the world — and the present day Helena still looks quite pretty.

I don’t remember what the song was about, but I remember that there was some lively choreography where she was lifted up in the air several times. At one point she played something that should look like violin strings while being held in the air — a bit amusing, but nice to look at.

Next year the show will be in Athens, for the first time in the history of the Eurovision Song Contest. Seen in that light, it’s only fair that Greece wins after having tried to do so in 31 years :-)

The Gospel of Tux is online again

Tux the Linux penguin At my old site I had a copy of the wonderful Gospel of Tux — so here it is again!

I’m not quite sure where this text comes from, but I’ve found it posted at lots of places around the Internet. Credit goes to “Lennier” or whoever actually wrote it.

Now using smart links!

In addition to my enhanced Markdown plugin, I’m now using Denis de Bernardy’s cool Smart link plugin. This lets me to link to my old posts using only their title, and to categories using only their name.