There was a writer who wanted to create important literature. He wanted to write words that would be read by many people. He wanted to write words that would make people laugh, words that would make them cry, words that would make them angry, words that would make them shake their heads in sorrow. He found the job he was looking for. He now writes error messages for Microsoft.
—E-mail forward, circa 2001
Some aspects of debugging can be learned by reading Microsoft's product documentation. Study http://msdn.microsoft.com closely enough and you'll learn all about the latest technological advances in debugging. But some aspects of debugging can be learned only through experience, or at least by listening to an experienced colleague. That's where you learn the principles that help you approach debugging problems more efficiently from the very start.
It's important to not focus solely on the technology of .NET. For example, Visual Studio .NET now offers a vastly improved debugger for SQL Server stored procedures, and we'll discuss how it works in Chapter 7. You'll find this debugger makes it far easier to track down problems in your stored procedures. But you may discover that in some cases, attacking the problem by debugging your stored procedure is the wrong approach, because the problem actually occurred earlier, for instance. Often, there will be an easier way that you should explore first. We'll examine many of the new .NET technologies in the following chapters, but first it's helpful to know some techniques for approaching a problem correctly.
In this chapter, we'll discuss six pieces of debugging advice:
Never ignore a bug that occurs early in a test to investigate a bug that occurs later.
Never forget the goal is to make the program work—fixing the bug is merely the means, not the end.
When something works one way but fails in a different way, focus on the differences.
Never assume the problem is a bug in the hardware, API, OS, etc. without reasonable proof.
Keep a few test computers on which debugging tools are NEVER installed—no exceptions. Period.
Step over all new code in the debugger as soon as you finish writing it.