Section 2: Debugging


Now that you're able to write code to a reasonable level, it's now crucial to get some skills in diagnosing mistakes and bugs within your code. They're only going to become more common and harder to investigate as you make more complex programs, so starting early on debugging will get you well prepared as you progress into the field. It's also an area I feel like isn't touched on enough in formal education, as I had to learn it on my own and those that I talk to who are still in school aren't that familiar with the tools that their IDE provides them. Anyways, enough rambling, let's get into debugging!

Bugs come in all sorts of different ways, but there's three main categories that they come in:

  1. Compile-time bugs: These are bugs within the syntax of your files. There's a whole range of these, some as simple as a missing semicolon, others as hard as an invalid datatype being used within a template. All of these however, are usually caught before you even run the program to being with. In most modern IDEs, these bugs will get some red underlining indicating that there's an issue with that section of code.
  2. Runtime bugs: These are a little more tricky, as they only occur while the program is running. However, these usually trigger an exception or a crash of some sort due to not utilizing the language properly or forgetting to check if something was null. While harder to spot than a compile-time bug, once they're hit they're easier to track down as the crash report usually reports the line number that the exception occurred on.
  3. Logical bugs: The hardest to track of them all, as the program won't initially indicate anything is wrong.

Since we've setup the IntelliJ IDE for Java Programming back in Section #0, learning how to utilize the debugger is crucial for fixing runtime bugs. The IntelliJ Documentation has a brief overview of how to debug a Java program, along with some videos showcasing how to use IntelliJ's tools to debug.
Since we've setup Visual Studio for C++ Programming back in Section #0, getting used to the debugging tools within the IDE will be crucial for fixing runtime bugs. The Visual Studio Documentation has a nice tutorial for some of the basic tools within the IDE. It'll be a good place to start for learning how to set breakpoints and navigate through the program while it's running.