惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tailwind CSS Blog
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
GbyAI
GbyAI
爱范儿
爱范儿
量子位
Martin Fowler
Martin Fowler
V
V2EX
博客园 - 三生石上(FineUI控件)
I
InfoQ
MongoDB | Blog
MongoDB | Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
N
Netflix TechBlog - Medium
D
DataBreaches.Net
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
U
Unit 42
Apple Machine Learning Research
Apple Machine Learning Research
H
Help Net Security
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
Engineering at Meta
Engineering at Meta

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Debugging Without Despair: A Systematic Approach for Norm...
Peter Parser · 2026-04-28 · via DEV Community

You've been staring at the same error for 90 minutes. You've added 14 console.log statements. You've tried random fixes from Stack Overflow. Nothing works.

You're starting to question your career choices.

Stop thrashing. Let's build a real debugging method.


🧠 The Hard Truth

Debugging is not guessing.
It's not "trying things until it works."

It's controlled investigation.

The best developers aren’t the ones who write perfect code.
They’re the ones who can systematically figure out why broken code is broken.


✅ Step 1: Reproduce It Reliably

If you can't make the bug happen on demand, you cannot fix it.

Bad:

"It crashes sometimes when I click the button."

Good:

"It crashes every time I click Submit with a username longer than 20 characters."

Action:

  • Write down exact steps
  • Create a minimal reproduction
  • Remove everything unrelated

🔍 Step 2: Read the Damn Error Message

Most developers don’t actually read errors fully.

TypeError: Cannot read property 'name' of undefined
    at getUser (Profile.js:42)
    at renderProfile (Profile.js:58)
    at ComponentDidMount (Profile.js:72)

Enter fullscreen mode Exit fullscreen mode

This already tells you:

  • 📍 Line 42 is the failure point
  • user is undefined
  • 🔄 Call flow: getUser → renderProfile → ComponentDidMount

Action:

Before changing anything, understand exactly what the error says.


⚡ Step 3: Binary Search Your Code

Don’t check everything. Cut the problem in half repeatedly.

The Method

  1. Log at the midpoint
  2. Check if it runs
  3. Narrow down the region
  4. Repeat

Example

console.log("1: entered function");  // ✅

console.log("2: before API call");   // ✅

// API call

console.log("3: after API call");    // ❌

Enter fullscreen mode Exit fullscreen mode

👉 Bug is between the API call and the next line.

Result: Eliminated ~75% of the code instantly.


🦆 Step 4: The Rubber Duck Method

Explain the bug out loud.

Yes, seriously.

Talk to:

  • A rubber duck 🦆
  • Your desk plant 🌱
  • Your cat 🐱

Why it works:
Speaking forces structured thinking.

"Then I update the state… wait… AFTER saving? That’s wrong."

Bug found.


🧨 Step 5: Check Your Assumptions (They're Wrong)

Every bug exists because an assumption failed.

Common Assumptions That Break Code

Assumption How to Verify
"This variable exists" console.log(typeof variable)
"API returned data" console.log(response.status, response.data)
"Loop runs" console.log("loop entered", i)
"Condition is true" console.log(isActive, role)
"Not cached" Add timestamp param

👉 Never trust assumptions. Test them.


🧪 Step 6: Use the Scientific Method

Treat debugging like an experiment.

Example:

  1. Hypothesis:
    API delay causes user to be undefined

  2. Experiment:
    Add artificial delay → bug appears

  3. New Hypothesis:
    Loading state isn’t handled

  4. Fix:
    Add guard before accessing user.name


🚫 Rule:

Never change two things at once.

You won’t know what fixed it.


🛠️ Step 7: Tools That Actually Help

✅ Use These

  • console.table() → clean object visualization
  • debugger; → real browser debugging
  • JSON.stringify(obj, null, 2) → deep inspection
  • VS Code breakpoints → precise control

❌ Avoid These

  • Random console.log("here")
  • Blindly copying Stack Overflow fixes
  • Rewriting code without understanding

⏱️ Step 8: The 20-Minute Rule

If you're stuck for 20 minutes:

Do one of these:

  • Take a 5-minute break
  • Ask someone
  • Write down what you know
  • Switch tasks temporarily

Don’t:

Grind for 3 hours and make it worse.


🧩 Real Debugging Session

// Bug: UI shows [object Object]

// Step 1: Reproduce
// Happens after search, not on fresh load

// Step 2: No error → logic issue

console.log(user);        // { name: "Alice" }
console.log(user.name);   // "Alice"

// JSX:
{user}        // ❌ "[object Object]"
{user.name}   // ✅ "Alice"

// Fix:
{user.name}

Enter fullscreen mode Exit fullscreen mode

Time to fix: 4 minutes


📋 Your Debugging Checklist

Keep this near you:

  • [ ] Can I reproduce it reliably?
  • [ ] Did I read the full error?
  • [ ] Did I isolate using binary search?
  • [ ] Did I explain it out loud?
  • [ ] Did I test assumptions?
  • [ ] Did I change only one thing?
  • [ ] Has it been under 20 minutes?

🔄 When to Stop Debugging and Start Over

Sometimes, rewriting is the correct move.

Signs:

  • Deep nested conditionals (3+ levels)
  • Same bug area repeatedly breaks
  • You don’t understand the code
  • No documentation + original dev is gone

Rewriting is not failure.
Leaving fragile code is.


💡 Final Thought

Debugging isn’t about being smart.

It’s about staying calm and methodical when your brain wants to panic.

The developer with a checklist beats the genius who guesses.


Next time you're stuck → go back to Step 1.

It works. Every single time.


— Someone who once spent 6 hours debugging a missing closing bracket