You are on page 1of 1

Programming "Style"

Some material in this and subsequent sections is adapted from the book "FORTRAN 90 for Scientists and
Engineering" by Brian Hahn, which was included on-line with the Fortran PowerStation 4.0 compiler.

A program which is written any old how, although it may do what is required, is going to be
difficult to understand when you go through it again after a month or two. Serious programmers
therefore pay a fair amount of attention to what is called programming style, in order to make
their programs clearer and more readable both to themselves, and to other potential users. You
may find this irritating, if you are starting to program for the first time, because you will
naturally be impatient to get on with the job. But a little extra attention to your program layout
will pay enormous dividends in the long run, especially when it comes to debugging. Some hints
on how to improve your programming style are given below.

 Make liberal use of comments, both at the beginning of a program unit or


subprogram, to describe briefly what it does and any special methods that
may have been used, and also throughout the coding to introduce different
logical sections. Any restrictions on the size and type of data that may be used
as input should be stated clearly in the comments (e.g. maximum sizes of
arrays.)
 The meaning of each variable should be described briefly in a comment at its
declaration.
 Coding inside structures (loops, decisions, etc) should be indented a few
columns to make them stand out.
 The GOTO statement should never be used, under any circumstances

You might also like