Welcome to AE Resources
Converted document Converted document

FORTRAN 90+: GOOD PROGRAMMING PRACTICES

There are some basic good programming rules to use to minimize compiler and run-time errors, as well to write code that can be easily understood and modified by others or in the future. Some of these include:
  • Write pseudo-code before ever starting to write code on the computer.
  • Always use comments to discuss what is happening, in particular if there are many operations or loops. Cite references (such as an AIAA paper) or discuss what variables are and if there is a potential for confusion.
  • For operations that involve loops or conditionals, indent the lines that are within the loop or conditional for easy identification.
  • Do not use implicit types.
  • Be consistent with the formatting and naming conventions, either as the author or updating someone else’s code. Use short names, but those that are recognizable, such as "temp" for temperature, rather than "A", which is not recognizable.
  • Put in checks for input errors and potential output/math problems - make sure the code ends “gracefully.” Make sure if the code ends using one of these statements that it explains why it ended. For example, “There was a divide by 0.0 during the Mach number calculation in module SPEED.”
  • Use lower case for code and upper case for functions.
  • Do operations on objects, not data structures.
  • Just because Fortran says “one can” does not mean “one should.“ It’s easier to read a code when there is one operation per line (and is properly indented).