The Debugging Mindset
I personally found this to be a poor article on the subject. There&#x27;s very little actual content about debugging, he spent more time talking about theories of intelligence than debugging.<p>I&#x27;ve recently been thinking about this, thinking about making a course. It&#x27;s my personal experience that his approach is flawed. Fundamentally, step one is not develop a theory. That is the worst thing you can do, it can waste a lot of time. I still sometimes guess what the problem is, but all I really use that for today is where to <i>look</i> and that&#x27;s sometimes a waste of my time as I skipped step 1.<p>Step 1 is recreate it. No theorizing, no thinking, no faffing around. Can you recreate the bug exactly? If you can&#x27;t, find out why. Talk to the bug reporter, find out what they were doing, this is a people skill you need to learn as a programmer. Maybe you need access to the live data to see the state an object is in. There&#x27;s only a tiny percentage of bugs (usually race conditions) that can&#x27;t easily be recreated. If you can&#x27;t recreate it, that&#x27;s when you turn to logging to try and catch the conditions to recreate it, but logging is the last thing you should try and I rarely ever have to add it (we&#x27;re talking 1% of bugs). I often see junior programmers littering code with log statements when trying to debug, I feel this is a bad method, but can understand the temptation, especially when they don&#x27;t really understand what the code is doing (an understandable position I was in in my earlier days).<p>Step 2 is isolate it. If the code is simple and it&#x27;s obviously one method, no further work needed. If the code is complex, you need to really isolate the exact problem. Say you&#x27;ve got the wrong value displaying for a basket total, where is that coming from? Is it not updating, or is the total function the problem? Isolate the exact step in the process that&#x27;s going wrong. Sometimes it&#x27;s hard to isolate and logging is needed again, but same advice as before, logging is a rare necessity.<p>Step 3 is make it easy to run a recreation. If you can run it in 10 secs or less, that&#x27;s great. If it&#x27;s one method of a complex web call, make a test endpoint that only calls that method that&#x27;s failing and exactly recreates the conditions. Then you can run it quickly without all the cruft. In an extreme case, this can be taking the code completely out of the context and putting it in a tiny standalone app.<p>Step 4 is read + understand the code. Is there an obvious logic bug? Don&#x27;t jump to conclusions. Still don&#x27;t get what&#x27;s going on? Step through the code, breakpoints. Understand what&#x27;s going wrong. Breakpoints and stepping is fine, inspecting variables, etc.<p>Step 5 is fix it. This should be fairly simple now. This is also the time to think about the future. Is this part of the code a constant headache? Is it buggy because it&#x27;s over-complicated? It might need a bit of a refactor to make sure this doesn&#x27;t happen again. This is a judgement call, unnecessary refactors are expensive, might even introduce new bugs, but over-complicated code will lead to more bugs. It not being written in your favourite style is generally not a legitimate reason to refactor.<p>Step 6 is testing the fix, recreating the conditions from step 1. Don&#x27;t rely on QA if you have them. Ensure you&#x27;ve done your job.<p>(Step 7 get rid of your logging statements + test it again! You just changed the code)<p>Now you can skip steps, be far less formal about it.  Sometimes it&#x27;s obvious. Sometimes it&#x27;s hard and you may need to iterate over 4&#x2F;5&#x2F;6 a few times. But never, ever skip steps 1 + 6. Recreate it. Test your fix. Because if you skip those steps, and you &quot;fix&quot; it, you don&#x27;t actually know it&#x27;s fixed.