A Brief Introduction to Debugging

iamboris's picture

If you've taken any development courses, or tried software dev on your own, you've most likely been doing this in one form or another. Debugging is a key tool in a developer's toolkit (one of many).

There are multiple ways to debug. There are two main ways that I use all of the time. First is in the form of output. Second is in the form of using the actual debug tools that come with IDEs (such as Microsoft Visual Studio). I will try to briefly explain the two. 

You can output variables and other values to a console or another variable to see what state your program is in, what the value of a variable is, and/or identifying the code path that the program takes. In most languages you can figure out how to output to a console by googling something like "insert-language-of-choice-here output to console". This method is most useful when you can't use a debugger, or just don't want to put a breakpoint in your code. 

Using a debugger can be a little tricky. It involves putting breakpoints in your code that will cause your program to pause (break) at that point in your code. Most IDEs will allow you to step over/into/out of particular from the breakpoints. It's also a good time to look at the call stack to see how you got to the breakpoint. You can also "watch" variables to see what their values are at that point in time (and probably change them if you wanted to).

These are two techniques that can be used to help you determine problems in your code. They help you find bugs so you can fix them (hence the term debug).

I find this to be very helpful when working in a new codebase. You can get a view of the guts of the program; up close and personal. I also use it a lot to determine how a particular control is invoked, or understanding how an object works. Seriously, if you find yourself feeling bored, stick a breakpoint in an unfamiliar area of code! You will learn a lot.

Happy debugging!