Script Valley
Debugging: A Systematic Approach
The Debugging MindsetLesson 1.4

What is a hypothesis in debugging and how to form one

hypothesis formation, falsifiable hypothesis, debugging hypothesis vs guess, narrowing fault location, one variable at a time

Hypothesis vs Guess

A guess is: maybe the database is slow. A hypothesis is: the query on line 42 is doing a full table scan because the index on user_id is missing, which I will verify by checking the query execution plan. Hypotheses are specific, point to a mechanism, and have a test that can disprove them.

How to Form One

Start with the symptom and ask: what change in my system would produce exactly this output? List candidates. Rank them by likelihood and by ease of testing. Test the easiest-to-disprove hypothesis first -- if it is wrong, you have eliminated it in seconds.

// Symptom: user sees stale data after save
// Bad: cache issue maybe
// Good hypotheses:
// H1: Cache TTL not reset after write
//   test: disable cache, does stale data persist?
// H2: Write goes to replica, read from primary
//   test: check DB config
// H3: Frontend local state not refreshed
//   test: hard reload after save

// Test H1 first -- easiest to rule out
const result = await db.query({ bypassCache: true, userId });
console.log('Fresh from DB:', result);

One Variable at a Time

Never change two things simultaneously. If you do, you cannot know which change fixed the bug. Revert every change that does not confirm a hypothesis before testing the next one. This discipline separates systematic debuggers from those who fix bugs and never understand why.

Up next

How to keep a debugging log that actually helps

Sign in to track progress

What is a hypothesis in debugging and how to form one โ€” The Debugging Mindset โ€” Debugging: A Systematic Approach โ€” Script Valley โ€” Script Valley