I haven't been thinking much lately.

Meow?

IntenseDebate Is No More!

18th of January

I’ve finally had time to redo some of the styling for this site, so I’ve given comments a makeover and switched back to WordPress’s comment system. Initially, I used IntenseDebate to avoid having to style the comments. It was a good idea, but unfortunately I never got the motivation to finish it off.

Oops!

Permalink | Start the conversation

Explicit Versus Implict Coding

18th of January

Konstantin Kovshenin recently posted on his blog about creating a WP_Plugin class. He posted an example of a class to fit his thoughts around it on Gist, and from there, discussion has taken place on how such a class would be implemented.

There has been a fair bit of discussion on my fork of Konstantin’s code about this, and I’ve been updating the class with new ideas as we come across them.

However, as is usual with discussion regarding any semi-complicated piece of code, there has been some disagreement on how best to hook methods in. Mike Schinkel is a fan of mapping method names directly to hooks, whereas I much prefer prefixing methods that I want hooked with either action_ or filter_. (We both agree that PHPDoc tags are a good idea though, although Mike also adds a @wp-nohook to ignore any methods.)1 I thought I’d further flesh out why I’m not a fan of mapping the methods directly.

Personally, while I see the merit in naming methods for hooks directly, I hate magic. I hate not knowing when my code is used, and I think one of the biggest strengths of WordPress is that this hardly ever happens. If I want something used, I explicitly declare that through add_action/add_filter.

Don’t get me wrong: I love making things easier for myself. One of my favourite pieces of code ever is one written by Morten Fangel that I use in almost everything I do: _sortArgs(). This piece of code will take an associative array, like array('a' => 'b') and map the variables to parameters to my function. Combined with $_GET and $_POST, it’s an extremely powerful tool. However, _sortArgs isn’t really that magical when it comes down to it. I’m specifying which parameters I want, and everything is explicitly written by me.

I can see the same thing with this plugin class. If I prefix a method with action_ or filter_ (or using PHPDoc tags), I’m explicitly stating that I want this hooked. On the other hand, a method like init is completely implicit. It happens to match a WordPress action, but that could be a coincidence.

As an example of where this would be a problem for me: I often write a method like admin_page for whatever page I’m adding to the admin. If I have things spread across several pages, I’ll factorise the common header bits and footer bits into admin_header and admin_footer. Except with implicit hooking, I’ve accidentally just hooked my footer method into the administration footer. Now, I have to undo that by specifying that I don’t want it hooked.

To hook implicitly requires that I know every action/filter in WordPress to avoid conflicting with them.

Even worse than this is that hooking implicitly breaks forward as well as backward compatibility. Let’s say I add a method called after_post which I call from another class in my plugin, so I need it to be a public method. Everything is going well, until WordPress adds a hook into templates for adding content after a post. Oops, suddenly, my plugin breaks through no fault of my own, and through something that core developers shouldn’t (and wouldn’t) have to worry about.

Hooking implicitly breaks compatibility in every direction, and is too magical. It is absolutely not the way to consume a public API.

Sidenote: A discussion also emerged on how to use priorities. Mike and I both agree (I think) on using PHPDoc, while Thomas Scholz prefers preferred suffixing the method (i.e. action_init_2). My problem with this is that distinguishing between an named init with priority 2 and an action named init_2 is impossible.

Edit: Thomas dropped support for priorities in the method name, which I initially missed. Thanks for the correction.

Edit 2: Updated with a footnote about Mike’s position regarding implicit/explicit hooking.

  1. Mike has informed me that he does support explicit hooking for published code, but implicit hooking for prototyping. I’m not a fan of this either, since I can forsee people forgetting to do so. []

Permalink | 7 comments

Think Different

6th of October

Here’s to the crazy ones. The misfits. The rebels. The troublemakers. The round pegs in the square holes. The ones who see things differently. They’re not fond of rules. And they have no respect for the status quo. You can quote them, disagree with them, glorify or vilify them. About the only thing you can’t do is ignore them. Because they change things. They push the human race forward. And while some may see them as the crazy ones, we see genius. Because the people who are crazy enough to think they can change the world, are the ones who do.

We’ll miss you, Steve. Thank you.

Permalink | Start the conversation

What’s Up?

27th of January

And, yet again, I’m falling into the trap of not posting. Despite the fact that I have at least four draft post sitting around, I haven’t had the motivation to post any yet. But never fear, I shall get around to it eventually!

So, here’s a quick update on what’s happening with me. I’ve begun my senior year in high school, with less than 10 months until I graduate. I’ve been slogging away at my projects, as per usual, and I’m hoping to get the SimplePie website fully migrated to Automattic’s servers some time in the next few weeks. The sooner that happens, the sooner I can push out a bug-fix release.

I’ve also had the pleasure of working on YesPlugins with Anthony Cole and Mark Bao, but I can’t reveal too much on this yet. Watch this space, as many things are yet to come. (Interested in working with us? Get in touch.)

I think that’s about it for now. I intend on keeping this journal up-to-date much more than previously, and with some luck, I can stick to that. Until next time, ciao.

Permalink | 1 comment

Random Antics

27th of August

Quite a while ago, I was online with some friends in Bad Company 2. We decided to make some explosive footage and compile it into a masterpiece. While we wait for producer Newsworthy to finish our actual in-game video, here’s some of the raw footage. Enjoy!

Permalink | Start the conversation

On the Lack of Posting…

21st of August

Yeah, I haven’t been writing here much. More blog posts will be coming as soon as I have time to write them.

Permalink | 2 comments

Silverchair Covers Yellow Submarine

29th of April

One of the best renditions I’ve heard of Yellow Submarine.

Permalink | Start the conversation

Typography Is Important

15th of April

A crash course to using typography. This is going in my folder with Five Simple Steps.

Permalink | Start the conversation

Campus Notes Version Two

14th of April

Jim Whimpey has just announced Campus Notes has gone completely free for all users. I’ve been using it for a while in the free mode, and now that the number of notes is no longer limited, it’ll definitely be replacing Google Docs for the majority of my documents.

Permalink | Start the conversation

iLounge’s iPhone OS 4 Breakdown

11th of April

Safari. “Google” has been replaced next to the keyboard’s space bar with the word “Search.” Ouch.

This makes a lot of sense, as to my knowledge, this is the only time the submit button on the keyboard is something other than “return”, “search” or “go” in Apple’s apps. It also appears to be allowing for the user to change search providers, though I’m not sure that this would be a good move UX-wise.

Edit: Forgot to mention “go” the first time.

Permalink | Start the conversation