1. The Rubber Duck Method Works
I used to think it was silly. Then I actually tried it.
Explain your code to an inanimate object (or a patient colleague). The act of verbalizing your problem often leads to the solution.
2. Binary Search Your Code
Instead of checking everything at once:
- Comment out half your code
- Does the bug still exist?
- If yes: the bug is in the uncommented half
- If no: the bug is in the commented half
- Repeat until you find it
This is surprisingly effective and much faster than random guessing.
3. Check Your Assumptions
90% of bugs come from incorrect assumptions:
- "The API must be returning..." → Check it
- "This variable can't be null" → Verify it
- "The loop is running" → Add a log statement
Write down what you think is happening, then prove each assumption with evidence.
TL;DR
- Talk to a duck (or colleague)
- Binary search your code
- Never assume - always verify
Debugging doesn't have to be frustrating. Sometimes it's just about having the right approach.