DEV Community

Learn AI Resource
Learn AI Resource

Posted on

Stop Pretending to Explain Code to Ducks—Use AI Instead

You know that feeling? You're stuck on a bug for 45 minutes. You open a new tab to ask for help, and by the time you've written out a detailed explanation of your problem, you've already spotted the issue yourself.

That's rubber duck debugging. It works because explaining forces you to think differently about the code. But let's be honest—finding an actual rubber duck every time is weird. Your teammates judge you.

Good news: AI is way better at this than waterfowl.

Why Rubber Duck Debugging Works (And Why AI Does It Better)

When you explain code aloud, your brain restructures the problem. You slow down. You notice assumptions you didn't know you were making. The duck doesn't need to respond—just existing forces clarity.

AI does the same thing but also responds. It can spot obvious mistakes you glossed over while explaining. It asks clarifying questions. It doesn't judge.

The Setup (5 Minutes)

Pick your tool:

  • Claude/ChatGPT: Free tier works fine. Paste your function, describe the problem.
  • GitHub Copilot Chat: Right in VS Code. No context switching.
  • Cursor: IDE built for AI pair programming. Honestly my favorite.
  • Local llama.cpp: If you're paranoid about sending code to the cloud (valid).

That's it. No setup.

The Process (That Actually Works)

Step 1: Paste the function

function calculateDiscount(price, userType, itemsInCart) {
  if (userType === "premium") {
    return price * 0.9;
  }
  if (itemsInCart > 5) {
    return price * 0.85;
  }
  return price;
}
Enter fullscreen mode Exit fullscreen mode

Step 2: Explain the bug in casual language

"So this is supposed to give the best discount, but when someone's premium AND has more than 5 items, they only get 10% off instead of the stack. I think the problem is the if statements are checking one at a time?"

Step 3: Let it respond

Most tools will immediately see the issue: your conditions don't combine. You're not checking both conditions together, so a premium user with 5+ items gets 10% instead of 17.5%.

Step 4: Ask a follow-up

"Should I use Math.max to pick the best one, or add them?"

Now you're actually thinking through the logic with a partner instead of alone in frustration.

Real Example: The Async Gotcha

I spent 30 minutes yesterday wondering why a promise chain wasn't executing. My mental model said:

const data = await fetchUser(id);
const posts = await fetchPosts(data.id);
return { data, posts };
Enter fullscreen mode Exit fullscreen mode

This should be fast enough, right? I was making one request at a time, but my brain was skipping over that detail while coding.

Pasted it to Claude, said "This feels slow", and boom—first response: "You're awaiting sequentially. Those calls are independent. Use Promise.all()."

I knew that intellectually. But I wasn't seeing it until I had to explain it to someone (or something) else.

The Patterns You'll Actually Spot

After doing this a few times, you start seeing the same bugs:

  • Off-by-one errors (when iterating or indexing)
  • Logic that should combine but doesn't (AND/OR confusion)
  • Async sequencing when you meant parallel
  • Forgetting to null-check after a filter
  • State mutations in React when you meant to create new objects

AI gets really good at spotting these because it's seen thousands of them.

When This Saves the Most Time

  • Authentication bugs: So easy to miss an edge case. Explain it to AI, it asks "What about the logout case?"
  • Race conditions: Describe your async flow, AI immediately sees the timing issue.
  • SQL queries: Paste your join. AI spots the missing WHERE clause or the cartesian product waiting to happen.
  • Regex patterns: Just paste it. Say what you're trying to match. AI can usually spot what's breaking.

The Bonus: It Teaches You

Unlike a real duck, AI explains why the bug happened. You learn patterns. After a few weeks of this, you start catching these bugs yourself before they even compile.

Make It a Habit

Next time you're stuck:

  • Don't spend 15 minutes trying to figure it out alone
  • Don't open a real question on Stack Overflow
  • Just open Copilot Chat or a new ChatGPT tab and explain it

You'll feel stupid for like 30 seconds. Then relieved for the next 30 minutes you just saved.


Want more practical dev tools and workflow tips? Sign up for LearnAI Weekly—real resources for actually building stuff, not generic hot takes.

Top comments (0)