Rubber Duck Debugging

Rubber duck debugging is a problem-solving technique where you explain your code and the bug you're facing out loud — traditionally to a rubber duck, but now often to an AI assistant. The act of articulating the problem clearly often reveals the solution. AI has become the ultimate rubber duck: it actually listens and responds.

Origin

Named after a story in 'The Pragmatic Programmer' (1999) where a developer would debug by explaining code line-by-line to a rubber duck on their desk. The insight: forcing yourself to explain a problem clearly often exposes the flaw in your logic.

Example

You're stuck on why your API returns empty results. You start explaining to Claude: 'The function queries the database where status equals active, then filters by...' — and mid-sentence you realize you're filtering by the wrong field. The duck effect strikes again.

Rubber duck debugging is proof that the best debugging tool is clear thinking. AI just made the duck a lot smarter.

How It Works

  1. You're stuck — Code doesn't work and you don't know why
  2. You explain the problem — Describe what should happen and what actually happens
  3. The explanation reveals the bug — Articulating the logic exposes the flaw
  4. You fix it — Often before the duck (or AI) even responds

Why Explaining Works

When code lives in your head, it's easy to skip over assumptions. When you explain it:

  • You're forced to be explicit about every step
  • Assumptions become visible
  • Gaps in logic become obvious
  • "Wait, that's wrong" moments happen naturally

AI as the Ultimate Rubber Duck

Traditional Rubber DuckAI Rubber Duck
Listens silentlyActually responds
You find the answer yourselfAI might spot it first
Can't ask follow-up questionsCan probe deeper
Always availableAlways available
FreeSometimes free

The AI Debugging Conversation

You: "My function should return users sorted by date, but they're coming back in random order."

AI: "Are you sorting in the database query or in JavaScript after fetching? If you're sorting after fetching, are you using sort() correctly with dates?"

You: "...oh. I'm sorting strings instead of Date objects."

Making It a Habit

When stuck for more than 5 minutes:

  1. Stop staring at the code
  2. Open a conversation with AI
  3. Explain what the code should do
  4. Describe what's actually happening
  5. Walk through the logic step by step

The answer usually appears before you finish explaining.