Intel fortran-80 Laptop User Manual


 
Programming Guidelines
7-4
This
is
just
a
'starter'
list. Certainly, any experienced
programmer
could
add
to
this
checklist. Rereading such a list frequently, like rereading
programming
manuals,
is
a
good
way to refresh
or
reconfirm
programming
knowledge.
7.2 FORTRAN Coding
Section 7.1 lists some general
programming
considerations. When coding in
FOR-
TRAN
specifically,
other
points should be kept in mind.
7.2.1 Functions And Subroutines
The
first point has already been
made
in
Chapter
5,
but
is
worth repeating. Use
functions
and
subroutines in a
program
wherever it makes sense
to
do
so. First
of
all, they reduce the
amount
of
coding
to
be done, saving time
and
reducing the
chance
of
error.
They also save processor
memory
by allowing
shorter
programs.
And,
most
importantly,
they break a
program
into
units
that
can
be separately pro-
grammed
and
debugged
and
that
also clarify its logical structure, making it easier to
understand.
7.2.2 GO TO Statement
The
GO
TO
statement should be used only when necessary.
The
ability to
jump
around
at
will within a
program
can be a strong
temptation
to
neglect logical plan-
ning. No painter would worry
about
painting himself
into
a corner
if
he could escape
by simply shouting
'go
to
exit.' When the
GO
TO
seems necessary, consider first
whether
an
alternative solution
that
would improve the logical structure
of
the pro-
gram
has been overlooked.
7.2.3 Crossing Unit Lines
The
ability
to
divide a
program
into
subprograms
is
a
major
benefit
of
FORTRAN.
It
also has some potential pitfalls.
Be
careful when using global variables, external
procedures,
and
variables whose values have been
computed
outside the
current
pro-
gram
unit!
Take
advantage
of
the capability provided by
common
memory,
but
be
aware
of
the interaction
among
all the
program
units
that
reference
common
memory!
7.2.4 Computing Variables And Constants
Complex calculations can frequently be simplified by breaking them
into
several
steps
and
computing
intermediate variables. This
is
particularly
true
if
such
variables are used several times
after
their value has been
computed.
Program
execu-
tion time
can
be reduced by using intermediate variables
and
the
program
is
general-
ly
more
readable. Like most
programming
tools, however, the use
of
intermediate
variables
can
be abused
and
requires good judgement.
FORTRAN-SO