I have a confession: I’ve written bugs before.
😱
But here’s the thing: bugs happen. What matters is having a consistent, reliable process for dealing with them—especially one that keeps you from fixing the same bug more than once.
Here’s the approach I use when a bug shows up:
Quick triage:
Is this bug worth fixing? If it’s clearly a one-off or edge case that’s not affecting users, sometimes it’s okay to leave it alone. Triage saves you from wasting time.
Replicate it:
Get it to happen again—ideally in a local or staging environment. This is usually the hardest step. Once you can consistently reproduce the bug, the fix often reveals itself.
Write a test that fails:
This is the step most people skip. Before you fix the bug, write a test that demonstrates it. This proves the bug exists and protects you from accidentally reintroducing it later.
Fix the bug:
With a failing test in place, write the code that makes the test pass. Nice and tidy.
Deploy (and celebrate):
Your test suite is stronger, your code is better, and you’ve earned a snack.
Most of all: don’t pay for the same bug twice.
Regression bugs are costly, embarrassing, and usually avoidable—if you write the test.