This chapter contains some general principles which should be observed in writing and testing programs. An attempt has been made to demonstrate them in the examples in the previous chapters.
1. Plan your programs
Do not attempt to write the FORTRAN code straight away. Write an outline as shown in the examples, showing the main steps in sequence. Use indentation to indicate the logical structure.
2. Develop in stages
The steps defined in 1. can initially be quite broad and general. Revise your outline as often as required, breaking down each main step into a sequence of simpler steps. Repeat this process until your steps correspond to FORTRAN statements.
3. Define variables and arrays
While developing your program as above, think about the main variables and arrays you will require to represent the information. Choose names which suggest their usage and write down each name with its type and dimensions (if an array) and a note of what it represents.
4. Modularise
Use functions and subroutines not only to avoid repetitive coding but, more importantly, to keep your program simple and its structure clear by putting the details of clearly defined computations in separate units.
5. Provide for exceptions
Your program should be designed to cope with invalid data by printing informative error messages rather than simply failing, e.g. due to attempted division by zero. This applies especially if your program will be used by others.
6. Clarity
When writing your FORTRAN code, use indentation to clarify its logical structure and include explanatory comments freely.
7. Testing
Once you have eliminated the syntax errors from your program and subroutines, try running them using suitable test data. Calculate what the results should be, and check that the actual results correspond. If they do not, you will have to revise some of the steps above to correct the errors in your logic. To determine the cause of an error, you may have to insert extra WRITE statements to print out the values of variables etc. at various stages.
Your test data should be designed to test the various logical paths through your program. For example, to test the quadratic roots program of Figure 7 on page 16, you should use data designed to obtain two, one and no real roots, as well as a value of zero for a.
[Contents] [Previous] [Next] [Home]
NDP77
http://www.ndp77.net
webmaster Massimo F. ARENA
webmaster@ndp77.net
2004:02:14:17:30:17