I continue to find gems scattered across Microsoft Visual Studio 2010; these ones are from the debugging story in the code editor window and are largely made possible as a result of Microsoft deciding to use WPF as their display engine for the IDE.
Here are a couple of very cool tips to help yourself out while debugging in Visual Studio 2010.
Pinning Watched Variables
You can now hover over a variable or object and pin it to the debug window. This expands on the idea of watches and puts the data right in the source code editor. You’ll see the power of this the first time you’re trying to see what’s happening to a set of data or variables through a loop.
Hit the thumb tack on the right to “pin” the variable.
Combine pinning with conditional breakpoints and you have some very powerful scrubbing capabilities. This is essential in my work as I am eternally sifting through 3500+ rows of data, looking for non-conforming values and objects.
Debug Comments
Once pinned, you can also add comments to your watched variables. Note that in the left-hand column of the editor there is a corresponding thumb tack (you’ll need that for later use). There is an expander in the mini tool window for your pinned variable that reveals a comment text box for you.
The comments are persistent from session to session, so the next time you run your code you’ll see what you’ve previously typed. This is great stuff.
Out-of-Debug Experience
Even better is that those debug comments stick around into your post-debug experience. When you finish debugging and return to your code editor the thumb tacks hang around. Hovering over a thumb tack reveals the pinned variable or object and shows the last value displayed in the debug session as well as your comments.
This works across source code files and is a real improvement over the tried-and-testing watch window: rather than a slew of watches from across a solution, variable values stay in context to the code you’re reviewing.
Get Good at Debugging
I swear that the single most beneficial thing you can do as a programmer is learn to use your debugger. This is even more important than test-driven development and writing unit tests. I have worked with too many “senior” programmers who don’t know how to attach to a running process or how to use breakpoints and watches to help solve logic or transformation problems.
These tips are hopefully an extension to your debugging tool bag.
"I swear that the single most beneficial thing you can do as a programmer is learn to use your debugger. This is even more important than test-driven development and writing unit tests. "
ReplyDeleteI dissagree.
If You use UnitTests You almost don't have to use debugger at all.
Hey Anon,
ReplyDeleteI posted my reply in a new post:
http://theycallmemrjames.blogspot.com/2010/02/no-tanks-please.html
Cheers,
-jc