Suicidal Code

July 13th, 2007

Some code is not meant to live forever. In particular, during development phases of projects, it can be very reassuring to know that a particular release of an application will have a short life-cycle, because you’ll be (relatively) assured that users aren’t accidentally running crufty old (development!) versions of the app.

The basic means of accomplishing this is to put a date check in your code that determines if a certain time has come and, if it has, refuses to run any longer. Anecdotally, I can tell you that lots of developers do something like this. But I can also tell you that lots of developers do it the error-prone, labor-intensive way. I did too, until I picked up a great tip from Brian Cooke a while back, that completely automates the process.

The laborious and error-prone method involves manually typing into your code a particular date in the future, and using that date as the test for whether or not to keep running. Brian’s brilliant observation was that the future date is almost always some number of days from “now,” where “now” is the date the code is being compiled. Using a gcc predefined macro, __DATE__, the code can know for itself when it was compiled, and build in an expiration date based on that value.

// Two-week expiration
#define EXPIREAFTERDAYS 14

#if EXPIREAFTERDAYS
   // Idea from Brian Cooke.
   NSString* nowString = 
      [NSString stringWithUTF8String:__DATE__];
   NSCalendarDate* nowDate = 
      [NSCalendarDate dateWithNaturalLanguageString:nowString];
   NSCalendarDate* expireDate =
      [nowDate addTimeInterval:(60*60*24* EXPIREAFTERDAYS)];

   if ([expireDate earlierDate:[NSDate date]] == expireDate)
   {
      // Run an alert or whatever

      // Quit!
      [NSApp terminate:self];
   }
#endif

By putting code like this in all of your projects, you have at your disposal a simple, error-proof way of releasing a build that will stop working N days from now. When you’re ready to release a non-suicidal version, just change the EXPIREAFTERDAYS preprocessor macro to 0. Nifty, eh?

PS: Thanks to Jon Trainer for inspiring this entry by thinking the idea was cool when I told him about it.

Update: Rosyna points out that dateWithNaturalLanguageString might be a dangerous method to use here, because it will implicitly use a different locale to parse the string, depending on the user’s language settings. Furthermore, the documentation for that method strongly discourages its use. Ironically though, the reason its use is discouraged, because it’s got a limited vocabulary and favors English, is probably just about right for parsing the date from GCC.

The GCC documentation describes the contents of __DATE__ as “eleven characters and looks like ‘Feb 12 1996’.” I’m not really sure how many locales this will or will not work correctly for, so I’m thinking the safe bet is to use a more explicit string -> date conversion format. I’m busy with something else right now but if anybody has a good capsule solution for this, please share it in the comments! Rosyna suggests offline that perhaps some POSIX date string formatter will do the trick.

Wil Shipley On iPhone’s “SDK”

July 9th, 2007

If I wanted to program in a crappy language just so I could get more customers, I’d switch to Windows, not stinking JavaScript.

Pretty much sums it up for me, too. Wil makes this point and about a million other cutting and accurate remarks about Apple’s sloppy presentation of web development as an “SDK” for the iPhone. It’s a common theme among developers that we feel burned not by the lack of an SDK, but by the fact that Apple expects us to believe that this is one.

iPhone’s AJAX SDK: No, thank you.

Interview With Ars Technica

June 28th, 2007

I met so many amazing people at WWDC, among them Jacqui Cheng and Clint Ecker of Ars Technica.

Imagine how honored I was when they invited me to be interviewed on video for the blog? I think it came out pretty well, all things considered. You’ll get a sense for my speaking voice, and also hear my words drowned out by downtown San Francisco traffic!

Ars at WWDC: Video Interview with Daniel Jalkut

Subscribe Less To Read More

June 27th, 2007

Data syndication has changed my life. And, if you’re reading this (or space-barring past it!), it’s probably changed yours, too. A long time ago, but not so long ago that there weren’t any good web sites yet, if you wanted a break from the daily humdrum of your job or life, you might find yourself methodically cruising your browser bookmarks, “just to see” if there had been any recent updates to your favorite web content.

Syndication, e.g. RSS, changed all of that. Now, instead of wasting hours clicking bookmarks and scanning visually for new material, you simply press the space bar in NetNewsWire. Again, and again, and again. Throughout the day, and possibly without paying much attention at all to the updated content as it whizzes by. Once you’ve space-barred through everything the web has to offer, you might even find yourself guiltily refreshing feeds, putting an undue burden on servers of the world just to feed your need for more inputs. Or is that just me?

Syndication has brought luxury of riches, such that I’ve overcompensated for the desire to always have something new to read, by oversubscribing to everything the world has to offer. Now I’ve got plenty to read, but I’m interested in almost none of it.

I have thought about culling my subscription list for some time, and occasionally have done so upon realizing that some alleged programmer’s blog is actually more often about her uninspired opinions of the local school board, or the Latin American drug trade, than about the programming topics I expected. It always feels good to drop one of these feeds with the knowledge that my space-barring thumb will be saved much future work.

Today I finally took a good look at Rands In Repose, a weblog about engineering management, but also about Apple, and about giving presentations, and about having a slightly cutting take on all that happens in the world, and damn it all, brilliantly written! It’s a rare instance of finding a weblog where I not only want to keenly monitor what comes next, but also want to dig deep into the archives to take in what came before. Other weblogs have inspired this reaction (e.g. Joel on Software and Daring Fireball), but these moments don’t come often. Content like this demands to be read, yet I often end up flagging it for later access, because I don’t have enough time right now. Where is all the time going? Space-barring through crap! (Or writing long-winded weblog entries … )

I unsubscribed from 20 feeds today and added Rands. The new “Attention Report” in NetNewsWire 3, combined with the existing “Dinosaur Report” makes it easy to identify candidates for the knife. In general, if I space-bar through something all the time, I trust that it will show up as unloved on the attention report. So far it’s been a “trust but verify” type of experiment. “But I love that guy! I’m sure this is a mistake. Double-click. Oh yeah, he’s a brilliant Mac programmer who writes mostly about the Chinese democracy movement.”

My closing advice? Unsubscribe to at least 10 weblogs today (possibly this one!), and add Rands. Expect and accept only the best when you next press the space bar. Then get back to work!