BSD 3 development
[unix-history] / usr / doc / ratfor / m1
CommitLineData
8340f87c
BJ
1.nr PS 9
2.nr VS 11
3.if t .2C
4.if n .ls 2
5.NH
6INTRODUCTION
7.PP
8Most programmers will agree that Fortran is
9an unpleasant language to program in,
10yet there are many occasions when they are forced to use it.
11For example, Fortran is often the only language
12thoroughly supported on the local computer.
13Indeed, it is the closest thing to a universal programming language
14currently available:
15with care it is possible to write large, truly portable
16Fortran programs[1].
17Finally, Fortran is often the most ``efficient'' language
18available, particularly for programs requiring much computation.
19.PP
20But Fortran
21.ul
22is
23unpleasant.
24Perhaps the worst deficiency is in
25the control flow
26statements
27_ conditional branches and loops _
28which express the logic of the program.
29The conditional statements in Fortran are primitive.
30The Arithmetic
31.UC IF
32forces the user into at least two statement numbers and
33two (implied)
34.UC GOTO 's;
35it leads to unintelligible code, and is eschewed by good programmers.
36The Logical
37.UC IF
38is better, in that the test part can be stated clearly,
39but hopelessly restrictive because the statement
40that follows the
41.UC IF
42can only be one Fortran statement
43(with some
44.ul
45further
46restrictions!).
47And of course there can be no
48.UC ELSE
49part to a Fortran
50.UC IF :
51there is no way to specify an alternative action if the
52.UC IF
53is not satisfied.
54.PP
55The Fortran
56.UC DO
57restricts the user to going forward in an arithmetic progression.
58It is fine for ``1 to N in steps of 1 (or 2 or ...)'',
59but there is no direct way to go backwards,
60or even (in ANSI Fortran[2]) to go from 1 to
61.if n N-1.
62.if t N\(mi1.
63And of course the
64.UC DO
65is useless if one's problem doesn't map into an arithmetic progression.
66.PP
67The result of these failings is that Fortran programs
68must be written with numerous labels and branches.
69The resulting code is
70particularly difficult to read and understand,
71and thus hard to debug and modify.
72.PP
73When one is faced with an unpleasant language,
74a useful technique is to define
75a new language that overcomes the deficiencies,
76and to translate it into the unpleasant one
77with a preprocessor.
78This is the approach taken with
79Ratfor.
80(The preprocessor idea is of course not new,
81and preprocessors for Fortran are especially popular
82today.
83A recent listing [3] of preprocessors
84shows more than 50, of which at least half a dozen are widely available.)