OFF-TOPIC / FIELD NOTE
Im George Costanza. Lord of Debugging!
Strong tea. Weak evidence. An extremely confident theory.
My first theory is always excellent. It explains the crash, clears me of responsibility, and requires absolutely no changes to my code. A beautiful theory. Then someone asks for evidence and ruins the afternoon.
This is the Costanza school of debugging: a minor technical inconvenience becomes a personal grievance, then a constitutional issue, then a reason to put the kettle on.
The compiler has a motive.
The compiler has been moving things around. The scheduler refuses to respect my timing. The allocator gave my address to somebody else. Everybody has an explanation. Nobody has apologized.
Meanwhile, the debugger is attached to yesterday’s binary. I discover this quietly. There is no need to involve the entire organization.
The opposite experiment.
If every instinct says the pointer is valid, check its lifetime. If every instinct says the lock is held, find the path where it is not. If every instinct says this will take five minutes, make a full pot of tea.
Doing the opposite is a surprisingly useful research method when your usual method is defending the first explanation because you have already told three people about it.
A highly professional debugging ritual
- Declare that this cannot possibly happen.
- Watch it happen again.
- Pour tea into an ince belli glass. The glass has a stable ABI.
- Reduce the case until the evidence is too small to argue with.
- Fix the bug. Describe the previous six hours as “eliminating alternative hypotheses.”
There is a temptation to look busy while the test runs. Frown at the terminal. Shuffle a window. Sigh like the machine has breached a contract. Unfortunately, the race condition is unimpressed by office politics.
So: keep the raw trace, question the convenient assumption, refill the tea. If the bug disappears, reproduce it before taking credit. If it returns, we were never finished investigating.
The bug was in my code. I still feel the compiler could have handled the situation better.