The Fast Show said:
Debugging is very much like making love to a beautiful woman..
Well, it's not really. It is more like trying to discover fundamental particles. You throw all kinds of custard at it in the hope that something sticks. Well, not custard, but other high-energy particles/radiation. And you are not hoping that something will 'stick', but for evidence of new particles. Not a particle itself: it is not going to jump up and say "Here I am!". You are looking for remnants, a history, a trace of the particle.
I assume that boffins eliminate all the known-knowns first. That is, they remove the traces that are expected, or understood, eventually identifying the traces that are, as yet, unexplained. Debugging is kinda similar (sort-of..).
When debugging, especially when you are relatively new to it, it is acceptable to throw all kinds of custard. But some basic steps are:
- Split complex statements into individual lines.
- If necessary, introduce new variables to store intermediate values.
- Print out the values of your variables. Use messageboxes or console-print statements. (In Visual Studio you can print to the Immediate Window using Debug.Print.)
- Introduce temporary, test values, that you know should work.
Try anything that occurs to you. Anything that might yield a clue, or at least eliminate some possibilities.
More formally, you need to become familiar with the debugging tools of your editor of choice. You will then be able to step through your code, examining all variables as you proceed, often being able to test expressions. I have a tutorial for VB.NET:
Debugging in VB.NET
(There is an equivalent pinned in the C# tutorials section.)
Debugging is an investigative process. You are not necessarily looking for a direct answer to a direct question. You are looking for clues to the whereabouts of Mr, or Mrs, Error.
As you become more experienced you will be able to target, and refine, your debugging steps. To get to this level though, be willing to try anything and everything!
More experienced programmers fall into a different trap. They tend to over-confidence and can miss some very obvious things! (I speak from experience..)
The clues you uncover will eventually lead you to the problem and, hopefully, the/a solution. Once the problem is found you can then, of course, take him (or her) into, erm.., custardy (Groan).
5 Comments On This Entry
Page 1 of 1
Page 1 of 1