Good Programming Practices- contd.
· Defensive programming: Prevent run-time errors by checking for them before any risk operation. Never assume exact equality of real values. Produce a meaningful error message directly related to the specific error. Never stop if something useful can be done. Check to see that you handled the null cases properly.
· Use of submodules: Protect input parameters. Avoid procedures with side- effects. Make all temporary variables local to the submodule where they are used. Where appropriate use signal flags to return the status of a computation to the calling program.
· Program Independence: Try to develop programs that are independent of: (a) the machine environment (portability) by using standard FORTRAN 77, by avoiding machine dependent constants, by avoiding specific collating sequences, by localizing and identifying unavoidable machine-dependent information. (b) The data set (generality) by making key data values parameters to procedures not local variables, by considering how to achieve generality from the earliest stages of program design and specification.
· I/O behavior guidelines: Always identify the input you are requesting. Avoid programs that trap the user in an infinite loop demanding correctly structured input, without offering assistance in preparing it. Use a “help” mode to aid users prepares input. Have users supply input in a form most natural to them, not to the program. Use defaults to reduce the amount of input data required for flexible programs.