fighting the lack of good ideas

ask the right question

If you’ve never read Programming Pearls by Jon Bentley, and especially chapter 1, you should. Even before finishing this post. Even if you never write a program or touch a computer.

Now that that’s out of the way, I can continue.

The biggest issue in answering any question is not the answer – it is determining what the asker actually meant when they asked you the question. I, as many other people I know, always start by answering the question I was asked. However, often as not, that was not the question they actually wanted answered. They didn’t know it wasn’t the question they wanted answered, but it wasn’t.

In Bentley’s book, he describes a programmer who needs to sort a list of approximately 10,000,000 items several times per hour on a very limited machine (it was originally written in the early 80s). After spending several minutes helping his programmer friend noodle-out a solution that might take about 2 days to write and about a minute to run each time, he twigs onto what he says he should have asked before answering his friend’s question: “what are you sorting, and why?”. Turns out his friend needed to sort a list of 7-digit numbers, with no duplicates allowed. Why? Well, that was an easy answer, too – he was working with a list of all of the assigned toll-free 800 numbers and needed to be able to ensure that any new ones beings requested and handed out weren’t already taken.

Knowing now what the end goal of the programmer’s question was, Bentley suggests a far simpler method that doesn’t even entail sorting – since the list to be sorted was known to be just 7-digit numbers, he could think about the problem as marking down in a tiny structure whether or not a given number was in use, and if it was, it wasn’t available.

Without going into the exciting computer science applications Bentley brought out (because, of course, you just read the first chapter :)), I want to emphasize how important it is to ask the correct question.

Far more times than you could ever realize, you will be asked a question that wasn’t at all what the asker intended. A common example, “do you know what time it is?” “Well, actually, I do.” I do this to people quite frequently, and not just because it’s fun to mess with their heads, but because I figure the question you ask is the one you want answered. When this turns out not to be correct, a follow-on question is asked that more accurately describes what they’re wanting to know: “would you tell me the time, please?” Ahh, there’s the difference – a question that might actually yield a useful response.

That’s a humorous, and perhaps trite example, but let me give another. A few days ago, a friend of mine taking an operating systems class in graduate school called me up for help with a program he had to write in C. Unfortunately for him, most of his undergraduate programming classes dealt with Java, and C is simply different.

His task was to write a program that would accept a sequence of typed characters, break that list up into the separate elements it contained based on whitespace, and return that list. What he asked me was to help him fix his program to do what I described, but he didn’t tell me what the program was doing, just if I could help him get around the errors he was getting when he tried running it.

Ah hah! After helping him for about 20 minutes try to fix the routine he had written, I finally remembered to ask him what his assignment was. As soon as he told me, I suggested he use a prewritten library call that exists in every C programming environment – strtok. strtok just happens to do exactly what he was describing (if you follow the instructions on how to use it) – it will break-up a string of characters based on some split character, and return the little chunks as ‘tokens’.

Another recent example was that I wanted to get a half gallon, or so, of fiberglass resin. Not fiberglass, and not the hardener that turns it into epoxy, just the resin. In popping out to my local Lowes, I thought about what I would need to ask Customer Service to find out what I wanted to know. Knowing that fiberglass resin is typically sold in conjunction with fiberglass cloth, I decided to ask if they sold fiberglass cloth. It wasn’t what I really wanted to know, but I was pretty sure it would tell me what I actually wanted to know.

That took some effort on my part, like knowing the complementing products to what I wanted, but was worth the effort because it got me what I wanted to know, that yes, in fact, Lowes sells fiberglass resin.

Asking the correct question is always worth your time and effort. Instead of spending 20 minutes debugging my friend’s program, I could have just spent 2 pointing him at the right library. Admittedly, asking the right question is not always easy, and it may only be possible to ask the right question after asking several not-so-right questions. But getting to the actual nugget that you need to know to help someone, or that will give you back the result that you need is worth it. Every time.