Focused view of a computer screen displaying code and debug information.

What Coding Taught Me About Asking the Right Question

The hardest bugs I’ve chased were never hard because of the code. What made it hard was the question I was asking while I chased it. I kept asking the wrong question, and the right one never came up, so the fix stayed hidden even though it was small. Ask the question precisely, and the fix usually follows. Ask it vaguely, and you will take the long way to the same fix.

Why a Vague Question Produces Vague Code

The question you ask decides the code you write. That sounds obvious, and it is the easiest thing to forget once a deadline starts pressing, which is why I slow down at the exact moment everyone wants speed.

A vague question produces vague code because it gives you no way to tell a wrong answer from a right one. Ask to make it faster, and you get a week of guessing. Faster at what, under what load, for which users, and measured how? Until those answers are in the question, every change is a guess, and the changes only look like progress while the real problem stays untouched.

How a Precise Question Changes the Work That Follows

Ask which query runs on every page load and what it costs, and you get a fix by lunch. The difference is never talent. The difference is the question, asked precisely, before anyone opens an editor.

A precise question does three things at once.

  1. It names the behavior you expect and the behavior you actually see.
  2. It narrows the place where the two can differ.
  3. It gives you a way to know when you are done because the answer either matches the expectation or it doesn’t.

In other words, the question becomes the test, and the code becomes the answer to that test.

The Questions That Reveal a Bug Faster Than a Debugger

Before I open a debugger, I ask a short list of questions, and I write the answers down.

  • What is the program supposed to do, in one sentence? If I cannot say it in one sentence, I do not understand the problem yet.
  • What does it actually do, with one concrete example? An example with real input and real output beats a general complaint every time.
  • When did it last work, and what changed since then? The change is often the clue, and it is often smaller than the bug looks.
  • Can I make it happen again, on purpose? A bug I can reproduce on purpose is a bug I can test a fix against; a bug I cannot reproduce is still a question I have not asked well enough.
  • What have I already ruled out, and how do I know? Ruling something out is progress, as long as the ruling out is based on evidence, rather than on a feeling that it should be fine.

Asking these questions will often lead to a hypothesis about the cause, and a hypothesis is worth more than a day of random changes because it can be tested and disproved.

The wrong questions were not wasted time. Each one ruled something out, and each one brought the right question closer. That is progress too, even though no wrong question fixes the bug on its own. The list above is the faster way to reach the right one.

The Question Comes Before the Code

Write the question down. Make it specific enough that a wrong answer would be visible. Then, and only then, you can start building. The question comes first because it states the outcome you expect, and the code exists to produce it.

The written question protects you in two ways. First, it keeps the work honest when the deadline presses because the team can point to the question and ask whether the code answers it. Second, it protects the next person who reads the code because that person can see what problem the code was meant to solve, rather than guessing from the solution alone.

I keep the question at the top of my notes for a task, in plain language, before any code appears. If the question changes, I change the note first, and the code follows. That order sounds slow, and it is the fastest way I know to write code that lasts.

What This Means for You

The next time a task feels stuck, stop and look at the question before you look at the code. A stuck task is often a vague question wearing a code problem as a disguise, and a sharper question will often dissolve a problem that a sharper tool could not touch. Write the question down, make it specific enough that a wrong answer would be visible, and let the code answer that question. The question is the work, and the code is what the question produces.