Visual Basic

A Guided Tour

We'll examine the role that management and developer attitudes play in helping to produce fewer bugs. One of the key ideas here is that most program bugs that reach production can be avoided by stressing the correct software development attitudes. Several studies have shown that programming teams are successful in meeting the targets they set, provided these targets are specific, nonambiguous, and appropriately weighted in importance for the project being tackled. The attitudes of developers are driven by these targets, and we'll look at ways of reinforcing the attitudes associated with low bug rates.

Then it will be time to get our hands dirty. You probably remember those medieval maps that used to mark large empty regions with the phrase "Here Be Dragons". We're going to aim for their Visual Basic 6 equivalent, boldly venturing into the regions labeled "Here Be Nasty Scaly Six-Legged Hairy Bugs" and looking at some issues directly related to Visual Basic design and coding. We'll see where some of the more notorious and ravenous bugs are sleeping and find out how we can avoid waking them-or at least how we can avoid becoming really tangled up in them. At this point, we'll sometimes have to delve into rather technical territory. This journey into technical details is unfortunately inevitable when peering at creatures worthy of some of H. R. Giger's worst creations. Once you come out on the other side unharmed, you should have a much better appreciation of when and where Visual Basic developers have to be careful.

In the final section of this chapter, we'll look at some tools that can aid the bug detection and prevention processes in several ways. Microsoft seems to have established a virtual monopoly on the term "Wizard" to describe an add-in or utility designed to help programmers with some aspect of code development. So casting around for a suitable synonym, I came up with "Sourcerer" (thanks, Don!) instead, or perhaps Sourceress. Three such tools are demonstrated and explained.

The three sourcerers

The first tool is the Assertion Sourcerer, an add-in that supplements Visual Basic 6's Debug.Assert statement and allows you to implement assertions even in compiled modules, ideal for testing distributed components. Next comes the Metrics Sourcerer, also an add-in. It uses a couple of fairly simple measurements to estimate the relative complexity of your Visual Basic 6 project's procedures, forms, and classes. Several studies have shown that the longer and more complex a procedure, the more likely it is to have bugs discovered in it after being released to production. The final utility is the Instrumentation Sourcerer, yet another add-in. It adds instrumentation code to your Visual Basic 6 project to track all user interactions with your application's graphical interface. This tool can be invaluable in both tracking a user's actions leading up to that elusive program bug and showing exactly how different users use your application in the real world.

"Some final thoughts" sections

Throughout this chapter, many sections end with a recommendation (entitled "Some Final Thoughts") culled from both my own experiences and those of many other people in the IT industry. Acting on these suggestions is probably less important than understanding the issues behind them, as discussed in each section. These recommendations are just opinions, candidly stated, with no reading between the lines required.