On Searching

May 30, 2008

At trainings, sprints and other occasions I get to pair with a lot of bright people. What always fascinates me most is how they use tools to be efficient. What really saddens me, though, is when good developers waste time with a repetitive task. To me these observations were particularly interesting because I always thought I’m not using my tools very efficiently.Take emacs, for example. I use it, but I hardly use as many features and shortcuts as most others do. For instance, I don’t use auto-completion (I like to think I can type fast enough) nor do I know the keyboard shortcut for everything (“what was it again, Elbow + left-eyebrow RETURN toenail?”). So yes, you’ll have to make trade-offs between using tools and doing things yourself. Nevertheless, I think it’s a good idea to encourage people to use some on-board tools. One of the best tools that a computer can offer you, I think, is searching. So what I’m trying to tell you in this article is:

Let the computer find things for you!

My mom and dad use the computer a lot. And because they grew up with traditional filing strategies such as cabinets, binders and folders, they’ll recreate the same structure on the file system. Naturally, when they want to find something, they’ll open folder after folder until they’ve found the document they were looking for.

When I, on the other hand, want to find a file I open Spotlight and type some text from that file. It doesn’t even take a second and it finds emails just as much as events from my calendar. And it always finds the stuff. If it doesn’t find stuff, it’s not there. So it’s much more reliable than I ever would be. And what’s nicer, I don’t have to be so anal about filing everything away in the right folder. I’ve stopped filing the a good percentage of my emails into folders because Apple Mail’s search feature is so freaking fast (especially since the Leopard upgrade).

So searching is a great way to deal with unstructured data. Structure, in fact, becomes less important with good searching capabilities. Where was that PDF article on Supersymmetry that I read the other day? Was it sent to me via email? Did I download it from somewhere? Fact is, I couldn’t care less as long as I can find it right now. Not having to first go through my emails, then my browser’s download folder means I save valuable time when I need it again in a hurry.

Thus searching can make your work quite efficiently, especially when you’re a software developer, I think. Here are three examples of where searching can make a programmer’s work quite a bit more efficient:

  • Use grep when looking for a particular piece of code (e.g. when looking for the definition of a method, grep for def foo). Do I need to explain this? I hope not. I have no idea what people do on Windows, I suppose they use something built into their editor. Either way, don’t try to manually search a large codebase, it will cost you hours.
  • Use your editor’s search feature to look for a particular piece of code in a file. Sounds trivial, I know, but do a little self-experiment and watch what you do when you already know exactly what you’re looking up in a particular file, say, the Foo class. What I do, is this: I don’t bother taking a look around. I hit Ctrl+S in my emacs and start typing class Foo. Heck, I even use the search feature to navigate within the same file. Nothing can position the cursor as exactly as a quick search. Except the mouse, perhaps. So ok, using the search feature for navigation only works if you are a quick typist, and you’ll also want an editor that does progressive searching (searching as you type) and none of that “Search Next” stuff. But you know what, when you have a web browser that can do this as well, like say Firefox, finding important stuff in web pages can be just as quick. Just start typing the text and it’ll be highlighted instantly.
  • Use bash’s ability to search the command history when repetitively using commands on the command line. Don’t bother hitting the Up key for a 100 times, trying to find that hugely complicated command you typed in two hours ago. Hit Ctrl+R, start typing parts of the command and it’ll appear as you type. Didn’t know this feature yet? Ain’t it cool? Will it save you time? Maybe. Will it save you much aggrevation? Quite probably.

I’m sure this list can be extended. My advice is, as soon as you find yourself repetitively looking for something, ask yourself if and how it could be sped up with an automated search.

There’s also a nice corollary: If you want to make your own applications user-friendly, fit them with efficient and easy-to-use searches. I know that’s highly non-trivial, but it’s well worth it. Plone’s live search for instance is awesome, and I wish many other large websites had it as well.

Lastly, here’s a little anecdote that inspired me to write about this searching topic in the first place. Probably the best search business out there is Google. Their web, image, etc. searches are impressive, but I think one of their greatest search toys is Google Maps because it understands unstructured information as entered by humans and puts some structure in it.

Anyway, the anecdote:

The other day I needed the address of Sixt, a rental car company in Germany, in a city called Kassel. I could’ve opened the browser, gone to the Yellow Pages website, entered “sixt” into the form field for the business type or name and “kassel” for the location, and with some luck I would have gotten the address. With Google Maps, I open the browser to “maps.google.de” and just enter “sixt kassel” into the one and only text field. And voila, I get the address and telephone number of the Sixt office in Kassel (and as a byproduct, really, a map of the place).

It’s the same with Google Maps Directions. Most other systems will make you enter the start and end location using several input fields each. You’ll have to type in the street into one input field, the postal code in yet another and the town in a third. And if you’re crossing countries, by God, don’t forget to select the right one from a huge drop-down list. Not so with Google Maps. Just two input boxes, one each for start and end location. When you type in “Rome” to “London”, it knows you’re not travelling from Rome, Indiana to London, Ohio. What’s more, you can just copy’n’paste an address from anywhere into Google Maps, it will understand it.

Coming back to my original point of letting the computer do the searching for you: Having Google Maps find you a business address may not be that impressive (apart from the way it just “groks” your input). What’s really impressive is that it’ll find the things you’re looking for close to some location. Let’s say, for instance, I was stuck in the beautiful town of Torgau, Saxony, Germany and needed a rental car. “sixt torgau” is what I’d type into Google Maps, and voila, it finds the closest Sixt stations which aren’t in Torgau at all. The best thing is, I don’t even have to work out myself which one’s the closest. Just use Google Maps Directions from “Torgau” to “sixt torgau” and I get list of the closest Sixt stations sorted by distance.

Of course, the same thing works with airports, Starbucks cafes, and just about anything that’s on Google Maps. Personally I find the fact that I don’t have to go to various different websites to look for, say, all airports in Saxony, then figure out their distances to Torgau just to see which one’s the closest, incredibly cool. In fact, I think I’d like to see quite a few more DWIM (do what I mean) applications out there, and just for the fun of it, I think I’m going to write one myself.

4 Responses to “On Searching”

  1. Godefroid Chapelle Says:

    Sometimes, when searching through bash history, the first command you get is not the right one. You have the chance to cycle through other results by typing Ctrl-R again.

  2. betabug Says:

    “when looking for the definition of a method, grep for def foo”

    Inefficient. Start using the tags interface of your editor. :-p

  3. You can create a little shortcut in firefox for searches by right clicking into a search field and clicking on “Add a keyword for this search…” (or “Ein Schluesselwort fuer diese Suche hinzufuegen…” in german ;-)).

    That way I can open a new tab and enter “g linuxtag” (german linux conference) or “imdb indiana jones 4” and avoid having to enter the site’s name, waiting for it to load, searching on the site for it’s search-field, etc.
    And best of all, I don’t have to use the mouse to focus the search field, I just open a new tab and start typing along.
    I was really happy when I found this by accident, because it saves my time and nerves.

  4. […] this from Apple, even though OS X has had it first (it was launched with OS X Tiger in April 2005). I find search the single most important tool in a computer system and it’s highly underrated. It’s good to see that Microsoft puts […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: