# Systematic Debugging Quick Reference

## The Loop

```
Observe → Reproduce → Hypothesize → Test → Conclude → (repeat)
```

## Reproduce First

| Do | Don't |
|----|-------|
| Get exact steps, inputs, environment | Assume you know the repro |
| Capture logs, errors, screenshots | Fix before reproducing |
| Note when it works vs fails | Dismiss "sometimes" as unfixable |

## Binary Search

| Target | How |
|--------|-----|
| Input/data | Halve the input; which half fails? |
| Code | Comment out half; narrow to failing half |
| History | `git bisect` to find introducing commit |

## Stack Traces

| Read | Bottom → Top |
|------|---------------|
| Bottom | Entry point (e.g., event handler) |
| Top | Where it actually failed |
| Middle | Call path from entry to failure |

## Debugger Basics

| Feature | Use |
|---------|-----|
| Breakpoint | Pause at a line |
| Step over | Run line, stay in current function |
| Step into | Enter function call |
| Watches | Monitor expression values |
| Call stack | See path to current line |

## Common Pitfalls

| Pitfall | Fix |
|---------|-----|
| Fix symptom not cause | Find root cause; fix that |
| Assume without testing | Verify each hypothesis |
| Change many things at once | One change, one test |
| No repro | Get one before coding |
| Give up | Binary search; be systematic |

## Logging

| When | What to log |
|------|-------------|
| Quick debug | Inputs and outputs around the fault |
| Production | Structured; levels; correlation IDs |
| Minimal repro | Only what's needed to trace the flow |
