Recently I was trying to debug some code, and getting nowhere. So I went for a walk, and within about thirty seconds of being away from the problem realized I had to be looking outside the bounds of an array. When I got back to my desk, voila - that was the exact problem. So I kept a note of some of the other reasons I had bugs, and here it is:
1. Consider that whatever you are trying to achieve is, in fact, working. It is doing what you are asking it to do, but you don't notice or you are expecting something different to happen. This is a "cognitive dissonance" type of bug, and it's very hard to find because you can look at it all day, everyday and still not accept it.
2. You are convinced the input data is correct. However, despite looking at output data that's clearly complete nonsense for 15 minutes, you still don't realize that the input data isn't actually right at all. Again, like point 1, it's not the computer software that is malfunctioning, it's you.
3. Something worked that really shouldn't have worked (for example, an uninitialized variable didn't cause a crash), and when something else changed, it stopped working. So you end up looking at the thing you changed, but really it was the first thing that is broken. These are difficult to track down.
4. There is an error in the API you are calling, and it's simply not doing what you expect. Now this could be because there is an error in the API - that is, the API advertises that it performs a particular function, but it doesn't (this is rare in a mature API set). Or it could be a misunderstanding on yourpart, along the lines of 1 or 2.
What to do when stuck on a bug
1. Confirm your assumptions. Take a fifteen minute break, watch TV, go for a walk. Come back, and check that what you think you are doing is what you are actually doing.
2. Work backwards - try and work out how what the unexpected thing that is happening might actually happen. What would you have to change to make that happen? Have you accidentally done that? For example, perhaps you are loading in old test data by mistake.
My officemate also recommends running AppVerifier early and often to find potential issues.
Do you have any other bug classification stories and methods to share?