Archive for January, 2009

nil

Thursday, January 22nd, 2009

Objective-C has a neat little thing called nil, which represents the absence of an object. It’s like null in Java or JavaScript, or NULL in C, but with one important difference: you can call methods on it.

“Bwah?” you say, wondering why that would be a feature rather than a bug. Yes, that was my first reaction too. But after much use, I have decided that it is indeed a feature.

Send a message (i.e. call a method) — any message — to nil, and the response is always 0, i.e. nil. It’s counter-intuitive that nil is a good thing, because it seems like it would be a good way to mask errors.

And it can mask errors, but not usually. More importantly, effective use of nil cleans up tons of code that would otherwise be filled with if (foo == nil) checks.

Consider: object X holds a delegate “foo” which is notified about various events that happen to X. This delegate foo is connected to X by code external to both X and foo.

Now, this foo thingy isn’t really essential to the proper functioning of X. X doesn’t care about foo, foo cares about X. So why in the world should X be responsible for figuring out whether foo has been set or not?

Enter nil. X doesn’t need to know whether it’s delegate foo has been set or not, it just sends messages. If there’s no foo there, the messages disappear into the ether. Meanwhile X’s code is easier to read, because it doesn’t jump through hoops to guarantee that foo present.

I like nil. A lot.

(Update: some commenters have expressed concern about the effect of nil within arithmetic operations. It’s an understandable concern, but not relevant to Objective-C. Nil is an object type, not a primitive type. And as those of you familiar with C and Objective-C already know, primitive types don’t coerce to objects, and there’s no operator overloading. So nil doesn’t ever participate in arithmetic operations.)

App Store

Wednesday, January 21st, 2009

Go to download.com and look for software to buy for your computer. What’s the average price point? Probably around $30 to $50 for low-end software. Now go to the iPhone App Store — what’s the average price point there? Much lower, probably less than $10.

Why the difference?

The App Store demonstrates what happens when you simplify technology. Buying software for the desktop is a pain — you have to know which websites to visit, you have to know how to install the software, and you have to know what you’re getting into so you don’t end up with spyware. It’s not simple, it’s a huge time vacuum, and not many people do it.

For the iPhone, software is a consumer good. I mean consumers in the broadest sense — people who buy stuff from grocery stores, who shop at malls, who watch regular TV. You know, people who buy music on iTunes — those consumers.

How did Apple bridge the gap from power user to average consumer? Prominent access point, clean browsing, simplified and uniform installation, integrated billing, and quality control. And clean developer APIs that simplify development. The end-to-end cost of launching apps for iPhone is lower, so the price of apps is lower, and thus the risk of trying out new software is lower. The pool of software buyers expands, the pool of developers expands, and the ecosystem shifts. All this, and there’s not even a try-before-you-buy option.

It all seems obvious in retrospect. The question I ask now is: why doesn’t an “App Store” exist for desktop applications? Someone could make a killing.

Pandora for iPhone version 2.0

Tuesday, January 6th, 2009

Our lates version of Pandora for iPhone is available in the appstore. Progress bar, artist bios, Cover Flow song history, bookmark song samples, genre stations, and a few other nice things. Check it out!