BSD 3 development
[unix-history] / usr / doc / ratfor / m4
CommitLineData
8340f87c
BJ
1.NH
2EXPERIENCE
3.SH
4Good Things
5.PP
6``It's
7so much better than Fortran''
8is the most common response of users
9when asked how well
10Ratfor
11meets their needs.
12Although cynics might consider this to be vacuous,
13it does seem to be true that
14decent control flow and cosmetics converts Fortran
15from a bad language into quite a reasonable one,
16assuming that Fortran data structures are adequate
17for the task at hand.
18.PP
19Although there are no quantitative results,
20users feel that coding in
21Ratfor
22is at least twice as fast as in Fortran.
23More important, debugging and subsequent revision
24are much faster than in Fortran.
25Partly this is simply because the code can be
26.ul
27read.
28The looping statements
29which test at the top instead of the bottom
30seem to eliminate or at least
31reduce the occurrence of a wide class of
32boundary errors.
33And of course it is easy to do structured programming in
34Ratfor;
35this self-discipline also contributes
36markedly to reliability.
37.PP
38One interesting and encouraging fact is that
39programs written in
40Ratfor
41tend to be as readable as programs
42written in more modern languages
43like Pascal.
44Once one is freed from the shackles of Fortran's
45clerical detail and rigid input format,
46it is easy to write code that is readable, even esthetically pleasing.
47For example,
48here is a
49Ratfor
50implementation of the linear table search discussed by
51Knuth [7]:
52.P1
53A(m+1) = x
54for (i = 1; A(i) != x; i = i + 1)
55 ;
56if (i > m) {
57 m = i
58 B(i) = 1
59}
60else
61 B(i) = B(i) + 1
62.P2
63A large corpus (5400 lines) of Ratfor, including a subset of
64the Ratfor preprocessor itself,
65can be found in
66[8].
67.SH
68Bad Things
69.PP
70The biggest single problem is that many Fortran syntax errors
71are not detected by
72Ratfor
73but by the local Fortran compiler.
74The compiler then prints a message
75in terms of the generated Fortran,
76and in a few cases this may be difficult
77to relate back to the offending
78Ratfor
79line,
80especially if the implementation conceals the generated Fortran.
81This problem could be dealt with
82by tagging each generated line with some indication
83of the source line that created it,
84but this is inherently implementation-dependent,
85so no action has yet been taken.
86Error message interpretation
87is actually not so arduous as might be thought.
88Since Ratfor generates no variables,
89only a simple pattern of
90.UC IF 's
91and
92.UC GOTO 's,
93data-related errors like missing
94.UC DIMENSION
95statements
96are easy to find in the Fortran.
97Furthermore, there has been a steady improvement
98in Ratfor's ability to catch trivial syntactic
99errors like unbalanced parentheses and quotes.
100.PP
101There are a number of implementation weaknesses
102that are a nuisance, especially to new users.
103For example,
104keywords are reserved.
105This rarely makes any difference, except for those hardy souls
106who want to use an Arithmetic
107.UC IF .
108A few standard Fortran
109constructions are not accepted by
110Ratfor,
111and this is perceived as a problem by users with a large corpus
112of existing Fortran programs.
113Protecting every line with a `%' is not really a
114complete solution, although it serves as a stop-gap.
115The best long-term solution is provided by the program
116Struct [9],
117which converts arbitrary Fortran programs into Ratfor.
118.PP
119Users who export programs often complain that the generated Fortran is
120``unreadable'' because it is not
121tastefully formatted and contains extraneous
122.UC CONTINUE
123statements.
124To some extent this can be ameliorated
125(Ratfor now has an option to copy Ratfor comments into
126the generated Fortran),
127but it has always seemed that effort is better spent
128on the input language than on the output esthetics.
129.PP
130One final problem is partly attributable to success _
131since Ratfor is relatively easy to modify,
132there are now several dialects of Ratfor.
133Fortunately, so far most of the differences are in character set,
134or in invisible aspects like code generation.