Let’s start with a function to get all the videos on a device that looks like this:
Simple. Pretty much what you would expect in a “device” API, right? But now let’s assume that getVideos() requires a return trip to the web server to get the data. You have two options:
Now that’s not so bad, but consider the case where you also need an asynchronous call to get the device object. Now we have:
Ew… getting kinda nasty there isn’t it? Imagine if we also had to make an asynchronous call to get some details on the videos, and so on.
This could conceivably be used to recurse down a list of asynchronous callbacks (which I did find on the web somewhere but seem to find it at the moment). But I think this might lead to an even nastier looking API.
I’m sure on some level, this just requires a shift in thinking. But there’s a part of me that still longs for that two liner at the top of this post… sigh