I am a Bad Blogger

No matter how I edit and agonize before hitting the Post button, I always go back and edit some more (it's happening right now with this post). Sometimes I indicate that I've updated the post, but sometimes I'll throw in whole paragraphs without so much as a kiss my foot.

I do eventually decide to live with what I've got. I see old posts all the time that I'd love to rewrite, but I leave them alone.

I wonder if there is or should be a WordPress plug-in that allows readers to see old versions of a post.

"Ghost town" is "the author's own words"

A couple of writers I follow on Google+ have commented on this article by Dan Reimold calling Google+ "worse than a ghost town".

Two things. First, why does the title of the article put "Worse Than a Ghost Town" in quotes? The phrase is the author's own words from the article itself. He's not reporting something somebody else said. [That should be "First, I am a bonehead." Chris corrected me in the comments.]

Second, I agree with Guy Kawasaki:

I feel like it's a resort that the tourists haven't trashed yet.

I have a big backlog of stuff in my Google+ stream that I wish I had time to catch up on. Granted, a lot of it is from Guy himself, but there's plenty of good stuff from other people too.

That said:

  • I wouldn't mind seeing more of my friends on Google+, as opposed to people I know only by reputation.
  • Although posting on Google+ is pleasurable in the same way as writing a blog post, I don't see it ever replacing my own blog.
  • They really, really have to allow me to edit the excerpt they add when I post a link. It matters a lot to me to be able to pick an excerpt that enhances any point I am trying to make and that will make people want to click the link.

A commenter on Reimold's article points out:

Face book is a social network, but G+ is also an Interest network.

Guy makes a similar point but uses the word "passions". Not my favorite word, but I agree. When I say I want to see more of my friends on Google+, I mean my fellow Cocoa geeks and judo enthusiasts. There's a whole other category of social interaction I prefer to do on Facebook.

C pitfall: typo in variable initialization

Apparently C allows a variable's initialization to refer to the variable being declared, as in

int x = x;

I guess the reasoning is that by the time the compiler reaches the initialization on the right side of the "=", the declaration on the left side has allocated memory for the variable, so the variable may be referenced.

This language feature may have its uses, but it can also lead to subtle bugs. I just fixed a bug that boiled down to the fact that the following compiled and ran:

- (void)wtf:(NSString *)ping
{
   NSString *pong = [pong self];
   NSLog(@"%@", pong);
}

The first line of the method should of course have been

   NSString *pong = [ping self];  // ping, not pong

but due to copy-paste and variables looking alike, I didn't spot the typo until our QA guy reported a crash and his stack trace led me to this method.

By coincidence, the code had worked correctly for me every time in development. In the debugger, I printed the value of pong on entry, and it happened to be the value of ping, presumably because that was the leftover value that happened to be on the stack.

I don't think this is a compiler bug. I believe the C standard allows the incorrect code I wrote, for two reasons. First, I created a scratch project and compiled the above wtf: method verbatim with GCC 4.2, LLVM GCC 4.2, and LLVM compiler 1.7. Second, I vaguely remember someone posting a trick for creating variables with unique values for use as the "context" passed around by KVO. I think the trick used this feature of C.

Update: I think the KVO trick was something like

void *x = &x;

I guess there no reason to disallow this, since it's equivalent to

void *x;
x = &x;

So now that I think about it, my bug wasn't really related to initialization. I could just as easily have made my mistake this way:

- (void)wtf:(NSString *)ping
{
   NSString *pong;
   pong = [pong self];
   NSLog(@"%@", pong);
}

IKImageView's mysterious delegate

Martin Hewitson asked this question a little while ago on cocoa-dev:

Does anyone know what messages the delegate of an IKImageView will get? I can't find any documentation or examples.

I was surprised to find there is indeed nothing about this in the docs. I Googled "IKImageView delegate" and the top hit was page 2 of an article posted by Dave Jewell for The Register in 2008. The article lists delegate methods that seem to have been discovered via class-dump.

In 2010 the question was asked again and still not answered in the docs.

I hoped the methods might at least be declared in a header, but the following returns no results:

$ cd /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Quartz.framework/Versions/A/Frameworks/ImageKit.framework/Versions/A/Headers/
$ grep imageWillChange *

Apple's own IKImageViewDemo example code sets the delegate but never implements any delegate methods.

Searching StackOverflow does not find anybody asking this question, although there are plenty of other questions about IKImageView.

So here is a class that has been around since 10.5, that people are clearly using, and its delegate has never been documented? Why hasn't there been more of a clamor about this?

If you implement one of the methods listed in Dave Jewell's article, will Apple reject you from the App Store for using an undocumented API?

Jewell wrote:

In fairness to Apple, the lack of documentation is probably due – in part – to the complexity of the ImageKit framework.

I think that's way beyond fair. We all have bugs in our work, whether it's code or documentation, but I would find it odd for someone to excuse a glaring bug of mine out of "fairness".

I just filed rdar://10114629.

My WordPress plugins

I just replaced the WordPress plugin I use for enabling Markdown on this site. I've already forgotten the name of the plugin I got rid of. All I know is that it was giving me headaches when I went to clean up code snippets in people's comments. The right Markdown plugin to use is either PHP Markdown or PHP Markdown Extra (I use the latter) by Michael Fortin.

Here are all the WordPress plugins I use on this site:

  • Akismet. Spam blocker.
  • Markdown Extra. This is how PHP Markdown Extra is listed (without the "PHP") on the WordPress admin page for plugins.
  • MediaElement.js. For embedding video and audio. I used this to embed mp3 files in my two posts about Cantonese text-to-speech.
  • Unfancy Quote. Replaces the curly quotes that WordPress generates with straight quotes. I installed this so that code snippets don't get messed up.
  • WP-Syntax. Applies syntax highlighting to code snippets.
  • WP Super Cache. Page caching, aka protection from being Fireballed or Slashdotted. Hey, you never know.

By the way, both Markdown and syntax highlighting work in comments as well as posts. If you want to include Objective-C code in a comment, you can wrap it with <pre lang="objc"> and </pre> and it'll be syntax highlighted. One of these days I'll get around to making that clear in the comments UI itself. I should really look for a plugin that will allow you to preview comments, but that'll have to wait until the next iteration of my procrastination runloop.