|
To access the contents, click the chapter and section titles.
Sams Teach Yourself Visual J++ 6 in 21 Days
Make Each Class and Method Easy to UnderstandSure, youre the programmeryoure going to understand. But how about the poor guy six months from now who gets assigned a modification to your program? Do you want him to have to come to you for explanations? Or, how about you yourself six months from now? If youre anything like me, in six months youve worked on so many other things that youve forgotten many of the details regarding how the project works. Heres how you can avoid the problem: make every class, every method, and every variable easy to understand. Just how are you going to do that? Heres a list of suggestions:
Read Your Source Code and Simulate It MentallyBefore you run the debugger, run your mental debugger. Its far better for you to discover the problem by following the programs execution. You can simulate what the program does in your mind and follow the code just as if you were running the debugger. Why would this approach be better than running the debugger? Because you gain more value as the developer by mentally simulating the execution of the program. You can better understand exactly how the code works when you follow the code through in your mind. The next thing you must do is watch the variables. Be aware of their initial values and where their values change. Keep tabs on the more important ones, especially the ones you suspect are involved in the unwanted behavior. SummaryIn this chapter, youve learned what a debugger is and why its so important to software development. Youve learned how the Visual J++ debugger works. The navigation commands such as Step Into and Step Over are important things to know when you use the debugger, and they were all covered. The debug windows are important too, and familiarity with them is essential to good debugging. Effective debugging techniques were discussed. Besides knowing how to use the debugger, you need to know how to think through the processes. Q&AQ How can you make sure that a project has been compiled for debugging? A Go to the Build, Build Configuration menu item. Make sure that Debug is selected. If youre not sure whether all the modules have been compiled for debugging, select Build, Rebuild so that all the modules are recompiled. Q How can you step through a program with the debugger? A You can use several different commands. The Step Into command (F11) lets you step through source code one line at a time. The Step Over command (F10) lets you step through source code while stepping over any methods that are called. Q How can you view the contents of variables while debugging? A The best way is with the Watch window. Class variables and local variables can be added to this window. Variables youve added will display their values (contents) and their types. Local variables are best viewed in the Locals window. Q What is the Immediate window for? A This window allows you to evaluate expressions in immediate mode. For example, you might want to see the value of a variable or evaluate an expression with variables. Things such as nMyVariable * 5 can be evaluated. Q Whats in the Call Stack window? A The Call Stack window displays a list of all active procedures or stack frames for the current thread of execution. Q How are breakpoints used? A Breakpoints can be set anywhere in your program. When the debugger gets to a line of source code at which a breakpoint is set, it pauses execution of the program until you stop debugging or continue execution. Q Why is debugging so important to Visual J++ development? A Even though you designed the software and wrote the code, you might have missed some important factors that will cause your program to malfunction. This happens to the best of software developers. Q Are there additional approaches to debugging that havent been mentioned in this chapter? A The are probably as many ways to approach debuggings as there are Visual J++ programmers. Although this chapter presented some systematic approaches to debugging, your best bet is to develop your own approach that fits your way of thinking. Review Exercises
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |