A quick look at Dash for doc browsing

Dash, by Bogdan Popescu, is a brilliant developer utility that removes friction from two key areas of programming: looking up documentation and reusing code snippets. I haven't played with the snippets manager, and I've only played with the doc browser for a few minutes, but already I notice some excellent things:

  • It's fast to open and dismiss with a hotkey.
  • It performs fast live-searching as you type into the search field.
  • It includes a ton of docsets for a variety of languages and platforms, not just Cocoa and iOS. See the screenshot above for a complete list.
  • You can add your own docsets. The Kapeli web site helpfully points you to instructions for creating them.
  • It shows an Ingredients-like table of contents listing methods, properties, etc. for the class you're looking at.
  • It has options to search Google and StackOverflow, all while staying within the app.
  • It handles URLs of the form "dash://foo". If you click on such a URL, the Dash window will open and perform a search for "foo". This can be useful for things like emailing URLs as pointers to documentation, and putting links in one's own notes. Who knows, maybe someday there will be a web site called "Let Me Dash That For You" (although lmdtfy.com is already taken).

In Xcode, URLs are clickable when they appear in comments. Unfortunately, this doesn't work with dash:// URLs. I've filed a Radar requesting the ability to specify more URL schemes for Xcode to recognize. In the meantime, if one wanted clickable links badly enough, I suppose one could run a local HTTP server that converts localhost URLs to Dash URLs. Maybe Dash could have such a server built in? Would it be worth it?

More suggestions:

  • Add a Service that performs a search, much like a dash:// URL, but using the currently selected text in my frontmost application (which might be Dash itself).

    [UPDATE: @kapelimac informs me that Dash has had a "Lookup in Dash" Service for quite a while. My fault for not spotting it.]

  • Auto-detect method names. When I come across a method call like [obj doThis:xxx withThis:yyy] I'd like to be able to double-click one of the brackets to select the whole expression, and invoke the above-mentioned Service to perform a search. I'd like Dash to recognize that what I mean to search for is "doThis:withThis:". For extra credit, be able to detect a method name in any string that contains a colon. Or if that's too hard, any string that begins with a square bracket.

  • Add a social element such as Scott Anguish suggested a while back. This might not be a direction Bogdan wants to invest in, but it would be an interesting experiment. Of course, that's easy to say when I'm not the one doing the investing.

    [UPDATE: More from @kapelimac: "And another note: Dash has had Wiki pages for each method/class, but no one used them, so I removed them. And: "I plan on adding Disqus threads to all documentation pages, but I'm still waiting on a reply from @disqushelp if they allow it."]

I see from Dash's Twitter feed that Bogdan is quite actively working on the app, and in fact plans to start charging for it with the next release. I encourage you to check it out now while it is free, and to consider buying when Bogdan sets a price on it.

Liking SpeakerDeck

I'm glad I learned about SpeakerDeck from Samuel Goodwin, who used it to share the slides from his presentation at last month's CocoaHeadsNYC. I used it to embed Bob Clair's slides (also from last month) and again this month to embed Isaac Schmidt's slides.

SpeakerDeck seems great not only for sharing but for discovering interesting presentations. Henceforth, unless I find something about SpeakerDeck that changes my mind, the CocoaHeadsNYC slides will be at <http://speakerdeck.com/u/cocoaheadsnyc>. The only drawback I can think of is that too many embedded slideshows might bog down the load time of the CocoaHeadsNYC home page. If that turns out to be the case I'm sure I can tweak WordPress to show fewer articles per page.

Why no PC guilt?

I get the argument that Apple, which profits handsomely on the backs of cheap factory labor, has a special responsibility to improve labor conditions where it can. What I don't get is why PC users — not the companies but the hundreds of millions of customers — have been silent for so long, and why they were silent in all the years before Apple climbed to its current position at the top.

Well, maybe "silent" is not the word. PC users and hobbyists have long bragged about how much less they pay than Mac users for equivalent or greater horsepower. Yet, by this very argument, PC customers benefit far more from harsh labor conditions than Apple customers. And over the years many more Windows computers have been sold than Apple computers (another point of pride for the PC crowd). Which community has the greater guilt?

In the decades that Windows has dominated the desktop, why haven't PC customers used their power to force manufacturers to improve conditions? We never hear a PC hobbyist say, "I'm conflicted. I love the killer system I built for under $200, but I'm ashamed of exploiting people who have no right to unionize." We never hear noble offers to pay more for PC components, even as we are told the exact amount iPad owners should volunteer to pay so that Chinese workers can live a little better.

What's more important: humane working conditions, or saving twenty bucks on a graphics card that will let you play the latest game at 50 frames a second instead of 40? How many Xbox workers have to threaten suicide before somebody delivers a petition to Microsoft?

I'm being deliberately inflammatory here. I don't think there's a simple "me good, you bad" answer for either side. My point is that it's easy to point a finger if you never examine your own actions.

By the way, a really interesting book on migrant factory workers in China is "Factory Girls", by Leslie T. Chang.

Spock using a spatial UI

I was watching the very first Star Trek pilot, and I noticed that for one brief second Spock seems to use a spatial UI gesture to control the big screen.

If you have streaming Netflix, you can see for yourself right now. Perhaps you can check whether I'm mistaken. The episode is called "The Cage", and the moment I'm talking about is at 2:29. It looks like Spock swipes his finger in the air from left to right, causing the screen to change from a view of space to a map of some planets. He then says "Records show the Talos group has never been explored."

I learned from Wikipedia that although this episode was completed in 1965, it wasn't broadcast until 1988. Even with the 23-year delay, I wonder if it was the first example on TV of a spatial gesture-based UI, long predating "Minority Report" and the Kinect. Maybe not; I haven't watched all that much science fiction.

I'd like to see someone try to use this as a prior art argument in a patent lawsuit, as was done with the tablets in "2001: A Space Odyssey".

Spock gesture begin

Spock gesture end

Dumb comments on purpose

(Note: This is about comments in code, not the topic of blog comments which was debated recently by various bloggers.)

One of the first things they teach programmers about comments is, "Don't merely repeat in the comment what the line of code literally does." A laughable example such as the following is usually given.

x = y * y;  // Set x to the square of y.

In general I abide by this rule, but there is one exception: when I need a comment to turn a line of code into a section of code.

I use inline comments to break a block into logical sections. Taken by themselves, the comments tell a story. For example, here's a method that creates a cake, the way some people would write it:

- (xxx *)cake
{
    // Bake in oven.
    xxxxx;
    xxxxx;
    xxxxx;
 
    // Add icing.
    xxxxx;
    xxxxx;
 
    return xxxxx;
}

The above code doesn't look right to me, because it looks like the "return xxxxx;" is part of the "Add icing" step when it's not. To rectify this I add a dumb comment that puts "return xxxxx;" into its own section:

- (xxx *)cake
{
    // Bake in oven.
    xxxxx;
    xxxxx;
    xxxxx;
 
    // Add icing.
    xxxxx;
    xxxxx;
 
    // Return the result.
    return xxxxx;
}

I do something similar with methods that run through a gauntlet of reasons for possibly returning early. If they survive the gauntlet, I add a dumb "If we got this far…" comment.

- (BOOL)shouldEatIceCream
{
    // Is the ice cream poisoned?
    if (xxxxx)
    {
        return NO;
    }
 
    // Is it my birthday?
    if (xxxxx)
    {
        return YES;
    }
 
    // If we got this far, we shouldn't eat the ice cream.
    return NO;
}

I try to think of something more intelligent to say in these comments, but often I don't.