|
It can definitely be a challenge to write good code, and in fact, you’ll never get it right the first time. Programmers call the process of finding the errors in their code debugging, a phrase attributed to Grace Hopper, a twentieth-century military computer programmer. There are several things you can do to help yourself write good code and help find errors when they do occur.
The Formula Workshop contains a feature known as the call stack. If there is a problem in your code, the call stack will automatically appear with a drill-down path to show where the error occurred. It returns interim values as part of a call stack, with the line of code on the bottom of the stack being the line that actually encountered the error.
Crystal Reports provides built-in information on how your report is performing. From the menu, select Report > Performance Information to open the dialog shown in Figure 4.42. Use this dialog to choose between report definition information, saved data specifications, processing time information, and grouping information. You also have the option to save the data to a file, which allows you to return to it at any point.
Figure 4.42. Finding performance information
The following are a few tips and techniques that will improve the quality of your code and help you become an efficient programmer:
Space and format your code well; the easier it is to read, the easier it is to troubleshoot (debug).
Code a little, test a little, debug a little, then repeat; it is much easier to debug a little bit of isolated code than a huge set of code statements that might contain multiple errors.
Break large coding tasks down into smaller ones, using a function for each task. This will help organize your work and keep you from creating overly complex single functions.
Create a special section at the top of your report to use to test values as you’re working on new formulas.
Comment your code—you want to be able to read it in a few days!
If the code isn’t working, take a break from the computer and write the steps down in English to try to make sense of what you’re doing; often it’s our logic that is at fault, not the code.
Finally, have fun with what you’re doing! Writing code is a creative process; sometimes it’s a painful process, but ultimately, you’ll be proud of your work.
Use of content on this site is expressly subject to the restrictions set forth in the Membership Agreement | |
Conello © 2000-2003 Feedback |