In the last ten years Object Oriented Design and Object Oriented Programming has become increasingly popular; languages such as C++ and Eiffel have been hailed as the programming languages of the future, but how does Fortran 90 compare?
Programming paradigms have evolved over the years. With each successive
refinement of programming style have come improvements in readability,
maintainability, reliability, testability, complexity, power, structure
and reusability. The first computer programs were written in assembler
languages and primitive languages such as (the original) Fortran which
possessed only the single statement IF and GOTO statement to
control the flow of
execution; even procedures had to be simulated using a cunning
combination of ASSIGN and GOTO. Clearly the
directed graphs of these early programs resembled a bowl of spaghetti
with a vast number of logical paths passing through the code in an
unstructured fashion. Each path of a program represents a unique
combination of predicates which (some argue) must all be tested in order
to gain confidence that the program will function correctly. In
[4] Davis presents some estimations of the possible number of
paths through such an unstructured program: a 100 line program can have
up to possible paths.
The next phase of programming style introduced the concept of a
function; code modules could be written and the program
partitioned
into logical (and to some extent) reusable blocks. This had the effect
of reducing the complexity of the program (less paths) and improving the
maintainability, readability and overall structure. A good example of an
advanced functional language is FORTRAN 77. If the 100 line
program of above could be split into four separate functions then the
number of paths would be reduced to .
Functional programming forced the user to adopt better programming practises, however, there still existed many dimly lit back alleys where programmers can perform dirty tricks. In FORTRAN 77 one of the COMMON block is one classic example. Due to the absence of high level data structures (see next paragraph) users were often reluctant to supply seemingly endless lists of objects as arguments to functions; it was much easier to hide things `behind-the-scenes' in a COMMON block which allows contiguous areas of memory to be available to procedures. In FORTRAN 77 it is also easy to inadvertently retype parts of the memory leading to all sort of problems. For example, the following program was supplied to the Sun f77 compiler which generated one warning:
PROGRAM DUFFER DOUBLE PRECISION INIT COMMON /GOOF/ INIT, A, B CALL WHOOPS() PRINT*, "INIT=", INIT, "A=", A, "B=", B END SUBROUTINE WHOOPS() COMMON /GOOF/ INIT, A, B INIT = 3 A = 4 B = 5 END
the following output was generated:
INIT= 6.9006308436664-314A= 5.00000B= 0.
With the introduction of Algol the concept of
structured programming was born; chaotic jumps around the code were
replaced by compact and succinct blocks with a rigidly defined
structure.
Examples of such structures are loops and if blocks. Data was also
allowed
to be structured through the use of pointers and structures. Both these
features allowed for greater modularity, clarity and more compact code.
FORTRAN 77 missed the boat with regards to structured data, however, Fortran 90 has
corrected this oversight. With this new structure applied, our 100 line
program will now have a maximum of paths.
The latest and most fashionable programming paradigm is object-oriented programming. This style of programming promotes software reusability, modularity and precludes certain error conditions by packaging together type definitions and procedures for the manipulation of objects of that type. Fortran 90 does not have such an extensive range of object-oriented capabilities as, say, C++ but is comparable to (original) ADA and provides enough to be of great use to the programmer.