Effective Debugging in VC Express
---------------------------------
Preface
-------
This tutorial is aimed at the beginner, it aims to give a simple introduction to problem solving using Microsoft's interactive debugger, which is integrated into Visual C++ Express. Through this tutorial
Introduction
------------
Most of the time spent programming is time fixing problems with your code. Most of this time consists of trying to understand what the program actually does so that you can change it to what it should be doing. Writing a fix is easy once you understand the problem, understanding the problem is the hard part.
Solving problems is what programming is all about, this is the main addictive quality of programming. If it is something you don't enjoy then programming for fun probably isn't for you.
So, how do we understand source code? What are our tools and methods?
Reading, writing, navigation
----------------------------
The most obvious way to understand a program is to read it like a list of instructions, which is a lot easier if the variables have sensible names. For example, your compiler understands exactly what the following line does, but it doesn't have to work out why it is wrong-
float d=a+b+c/3.0;
This would be a lot easier if the variables had meaningful names-
float average = red + green + blue / 3.0;
<solution>
This problem is due to the order of evaluation, brackets are not used. Brackets aren't just for the compiler though, they also help humans understand what the code is doing. If brackets were used, the code would read like this:
float average = red + green + (blue / 3.0);
Clearly the average is not red plus green plus a third of blue, so it should be this:
float average = (red + green + blue) / 3.0;
</solution>
Indentation and separation
--------------------------
When navigating code you don't actually read it, you follow the shape of the code and only read the important lines. This is how all programmers read code so if your indentation is bad then nobody can read your code easily, including yourself.
<todo: horrible lack of indentation example>