Squash Bugs In Visual Studio
When something odd happens in a program that the developer certainly did not include in the code, a bug may have nestled in, and needs to be tracked down and fixed.
There is nothing quite like firing up a new program and watching it return something to standard output that looks more like a cat walked across a Cyrillic keyboard than the results one expected to see.
Developers working in Microsoft’s Visual Studio can take steps to help avoid the pain of invoking the debugger yet again, by proactively preventing some of the more common bugs from cropping up in code.
Author Peter Aitken has worked on several programming related books, including ones about Visual Studio.
He recently posted some commentary to InformIT that aims at placing the virtual flyswatter in developers’ hands and turning them loose on those bugs.
Even the most dedicated programmer who follows Aitken’s suggestions on good programming practices might still end up having to track down a belligerent byte or two of buggy code.
Just like the well-known maxim ‘divide and conquer’, breaking up one’s code can help a programmer narrow down the section where the bug lives.
Aitken suggests using breakpoints to find that critter.
“While the program is paused, you can take various actions to help find a bug,” he wrote.
Those actions include modifying the conditions that trigger the breakpoint, or specifying a hit count for each time the breakpoint is passed.
Once the program pauses, it’s time for the sheer joy of single-stepping through the code.
Aitken pointed out some useful keyboard shortcuts for when the program enters break mode. The developer can continue to the next breakpoint, or step into, over, or out of running the next statement.
Sometimes seeing the value of variables can help identify the problem.
By setting watch expressions for program variables through the Debug menu will show those values as the program executes.
If a variable reaches an unexpected value, that would indicate some kind of issue impacting it.
Go get those bugs. (Ok, maybe not those bugs. You know what I mean.)
David Utter is a staff writer for WebProNews covering technology and business.