A comparison of Fortran and C++
FORTRAN
Fortran Data Types -
Fortran uses basic data types with
reguards to variables.
Some simple examples include interger, real, complex,
etc.
Each variable should be definded in a declaration statement near the
beginning of a given program in Fortran.
This is easy to follow and
understand yet, it lacks the ability to create your own definded data
types.
Fortran Sequence Control -
Fortran uses the column
numbers of the program text to determine the function of each statement.
As a
general rule, the first 72 colmns of each line are scanned.
The first five
colmns must be blank or contain a numberic label.
Continuation lines are
identified by a nonblank, nonzero in column 6.
For someone new to
programming, this Is easy to see and understand.
Fortran Subprograms
-
Fortran uses two different types of subprograms which are called
functions and subroutines which is pretty standard to most programing
languages.
The functions can be thought of as functions that are seen in
math. An example would be A = 2x +3.
Fortran can take advantage of
subroutines to solve complex equations and functions by using the "subroutine"
contstruct.
Subroutines are vital to complex programs.
Fortran
Storage Management -
One of the great limitations in Fortran is its
inability to dynamically allocate storage.
In a large program which must deal
with problems are highly variable sizes, it is extremely valuable to allocate
storage based on the size of the problem.
Thus, a given computer can process
a mix of problems as long as the aggregate size is not too large.
Even
though Fortran does not allow dynamic storage allocation, we can conveniently
simulate it so that arrays can be established at run-time with whatever size is
necessary.
These storage allocation schemes are written entirely in Fortran
and do not require any machine dependent features.
Fortran takes
advantage of Stacks, Heaps, and Dynamic Data Structures in this
reguard.
Clarity, simplicity and unity -
In my limited
experiance with fortran, I is easy for another programmer to read and follow the
purpose of the program due to the rules defined in the control
structure.
Fotran is considered to be an older language and many seem to deem
that Fortran will fall to the way side. However, it preforms its defined
functions well.
Orthogonality -
Unfortuantly, Fortan is
limited with reguards to Orthogonality. Later developed languages improved on
this weakness and it remains one of Fortran's main
weaknesses.
Naturalness for its Intended Application -
Due to
Fortran being used mainly for scientific purposes, it remains a favorite among
scientists.
While this doesn't guarentee Fortran will preform the function
better than any other program, it is important that Fortran is successful in its
readability.
Support for abstraction -
Fortran 90 uses a very
practical and easy to use data abstraction capability.
However, C is given
the slight edge due to C's support of data structures as well as the ability to
code via objects.
Ease of program verification -
One of
fortran's main strengths is its compilers. Since fortran has been around for so
long, its different compilers have been inproved upon greatly over
time.
There are optional commands when running the compiler under unix to
list and show warning messages and inculde a debugger.
Programming
environment -
With my limited experiance with Fortran, I feel as though
the Fortran is very easy to use. Therefore I feel that the programming
environment is an advantge.
Fortran follows a very basic and easy to
undertand structure with the code. In my eyes, this is a strong advantage which
makes it easy to learn.
Portability of programs -
This is an
area where Fortran has fallen behind C and later developed programming
languages.
The ability to easily translate a fortran code to another language
is a difficult and costly opperation with most of the highly used programs being
so large and complex.
Cost of use -
Fortran should be used
for what it excels at.
Since it is easy to learn and understand, a programmer
must make sure that if they do not pass up a more complex language simply for
fortran's ease of use.
As stated previously, once company decides to use
fortran, it is not wise to have to switch over to a different language dut to
the nature of fortran's coding structure.
C++
Data objects and types -
C++ gives the programmer the
ability to create their own functions and classes which will be easy for the
individual programmer to follow and understand.
This is a huge advantage over
fortran.
C++ Sequence control -
C++ is very felxable with
reguards to how the text is placed in comparison to fortran.
C++ provides
control structures that serve to specify what has to be done with that
program.
C++ introduces the idea of "block of instructions" which is definded
by seperated semicolons but grouped by { and }.
Subprograms -
A major advantage over fortran is C++'s ability to seemlessly use sub
programs within its code.
It is very easy to modify pre-existing C++ code and
introduce further sub routines.
Storage management -
C++
offers tremendous felxibility in managing memory over Fortran such as static
storage and automatic storage.
There are a whole host of debugging utilities
available for C++ which help to improve upon the memory management of C++
code.
Clarity, simplicity and unity -
C++ excels in this area
in genearl. It could argued that Fortran excells in simplicty which I agree
with.
C++ has the ability to use libraries which let the programer used a
predefined structure to help aid in less time
programming.
Orthogonality -
With C++ being an object
oriented language, it is much eaiser to keep include complex functions that rely
on a totally seperate complex function.
The key is being able to ensure that
they stay related, yet seperate. C++ gives a programmer this added benifit by
being an object oriented language.
Naturalness for its Intended
Application -
C++ allows for very complicated programs. This is a huge
advantage yet can also be a weakness. It is vital that a programmer keep his
code readable for debugging purposes.
C++ can be used for virually any
application.
Support for Abstraction -
It should be obvious
that support for abstraction is one of the main advantages to programming in C++
for reasons stated previously.
Ease of program varification -
There are many good compilers and debugging tools available for
C++.
However, it remains vital that the programmer uses proper technique when
programming and makes use of the comment function to keep the program organized
and easy to follow for another programmer that would be involved with the
program or helping to debug.
Programming environment -
C++
can used in virtually any platform which is a huge
advantage.
Portability of Programs -
One HUGE challenge that
faces all C++ programmers is making sure their code is portable.
There are
many common rules for programming in C++ that will help the programmer ensure
their code is portable.
Being able to ensure you code is portable across
different platforms and compilers is a very important goal.
A good list of
basic rules for C++ portability can be found at
http://www.mozilla.org/hacking/portable-cpp.html
Cost of use -
There are many different compilers out there for C++. In the end, C++ is
a superior to Fortran simply because you can perform much more complex functions
in an object oriented environment.
The ability to ensure that the code is
portable amongst different platforms should be a major consideration when
deciding on a language to use for a programming
project.
Conclusion -
Fortran is the dominant
programming language used in scientific applications. From time to time,
so-called experts predict that Fortran will rapidly fade in popularity and soon
become extinct. These predictions have always failed. Fortran is the most
enduring computer programming language in history. One of the main reasons
Fortran has survived and will survive is software inertia. Once a company has
spent many man-years and perhaps millions of dollars on a software product, it
is unlikely to try to translate the software to a different language. Reliable
software translation is a very difficult task. Due to Fortran being easy to
learn one can start immediately to write programs that do useful calculations
for research research or class work. Fortran is the language used for most (but
not all) major scientific computing projects. C and C++ are certainly both
useful languages to know too, but they are a bit more complex and thus harder to
learn. C is stricter about grammar and syntax than Fortran. The best way to
learn C++ is to first learn C; And for scientists, the best way to learn C is
usually to learn Fortran first, as long as you also learn proper style and
develop good habits designed to carry over to C. When deciding upon which
language to use, the more complex the role the program will be, it is generally
advised to use C++.