Matthew Carson csc 415: Programming Languages



Download 41.77 Kb.
Date28.05.2018
Size41.77 Kb.
#51363



Fortran

Matthew Carson

CSC 415: Programming Languages

Dr. Lyle


October 21, 2014



Table of Contents


History of Fortran 4

Development 4

Fortran (1957-1966) 5

Standards of Fortran 5

Fortran 95 and Beyond 6

Overview 7

Names 7

Bindings 8



Scope 8

Data Types 9

Expressions and Assignment Statements 10

Statement-Level Control Structures 11

Subprograms 13

Object Oriented Programming 14

Concurrency 14

Exception Handling 14

Evaluation 15

Readability 15

Writability 15

Reliability 16

Cost 16

Bibliography 18


History of Fortran

Development


In the early 1950s, computer programming was still being done in assembly languages, utilizing extremely meticulous and lengthy code for even basic tasks. John Backus, a computer scientist for IBM, wanted a more practical way to write programs, and by November 1954, Backus and a group of programmers from IBM had produced a draft detailing the specifications for “The IBM Mathematical FORmula TRANslating System: FORTRAN”[Seb12]. As its name implies, FORTRAN1 was designed to make writing and translating scientific and mathematical formulas easier for programmers. In fact, during an interview with Think, the IBM employee magazine, in 1979, Backus said, “Much of my work has come from being lazy” [Ber07].

Backus was one of the first to realize the necessity for a “high-level language” for programming. Before the development of FORTRAN, assembly programming was the only way to program for computers, and this made computing inaccessible for other fields which would have greatly benefitted from the use of computers (mathematicians, scientists, physicists, etc.) It is due to this limitation of programming before FORTRAN that every programmer and language designer today owes a debt of gratitude to John Backus and his team of IBM programmers for developing the first high-level programming language as well as, arguably, the first compiled language.2


Fortran (1957-1966)


The first implementation of FORTRAN, known today as FORTRAN I, was released along with its compiler in April 1957[Seb12]. This implementation was very rudimentary, especially in terms of today’s programming languages, however, for its time was a revolutionary advancement in computer programming. FORTRAN I included support for basic programming necessities, such as: input/output, variables, and a selection statement as well as a loop statement.

In 1958, a newer compiler was developed for FORTRAN, which marked the beginning of what is now known as FORTRAN II. The biggest improvement with this new version of FORTRAN was the support for independently compiled subroutines [Seb12]. The addition of independently compiled subroutines decreased the amount of time necessary for debugging, and thus the overall design process of the program.


Standards of Fortran


FORTRAN II was replaced by a version of FORTRAN known today as FORTRAN IV in 1960. This version of FORTRAN was to become one of the most widely used programming languages of its time, according to Robert Sebesta [Seb12]. Some of the advancements in FORTRAN IV included: removal of machine dependent features and keywords, inclusion of the logical data type and explicit type declarations rather than the implicit declarations of previous versions. This version became so prevalent in the scientific and mathematical communities, as well as becoming a common educational tool, that the American National Standards Institute (ANSI) decided to standardize FORTRAN leading to the FORTRAN 66 Standard.

FORTRAN 66 was heavily based upon FORTRAN IV, so much so that the name FORTRAN 66 was never widely accepted, and most simply continued to call the language FORTRAN IV. This version has served for the basis of all subsequent Fortran implementations, including many of the constructs (main program, subroutine, function), data types, and input/output statements still used in Fortran today. However, there were still many shortcomings associated with FORTRAN 66, these shortcomings led to improvements to FORTRAN compilers and a new standard known as FORTRAN 77.

FORTRAN 77 improved upon the previous standard in a number of ways. Some of the most significant of these improvements were the inclusion of a blocked IF statement with the structure IF-ELSE IF-ELSE-END IF, where the ELSE IF and ELSE were completely optional, the character data type, and the IMPLICIT statement which will be covered in later parts of this paper.

Following FORTRAN 77 the next standard of Fortran was a major overhaul of the language. Aside from the official spelling change from FORTRAN to Fortran, Fortran 90 removed the fixed format of Fortran code which was associated with previous versions due to the use of punched cards [Seb12]. This free form input is more akin to programs that programmers of today are familiar with. This form makes code more readable, and thus, easier to design and debug. Along with this change, Fortran 90 included several aspects which allowed Fortran to compete with the current languages of its time. Fortran 90 allowed for dynamic memory allocation of arrays, included a case statement for multiple selection, and added the functionality for subprograms to be called recursively along with many other language features which had evolved through Fortran’s competitor languages.


Fortran 95 and Beyond


In 1997 a minor revision to the Fortran 90 standard was published as Fortran 95. The major addition to this standard was the addition of the FORALL construct which allowed iteration over arrays and aids in vectorization of the language. Though this standard was adopted almost twenty years ago, Fortran 95 is still the industry standard for Fortran, despite the Fortran 2003 and Fortran 2008 standards. The reason the latter standards are not industry standard is that the majority of their features are still not supported by the majority of compilers. Most of the features of the 2003 standard have been implemented by several compilers3, however, no one compiler fully supports Fortran 2003 so it would be best to use the features of this standard cautiously. The 2008 standard on the other hand has very few of its features supported by compilers at this time4, therefore the use of the 2008 standard is highly ill-advisable. For the above reasons, this paper will focus on the industry standard of Fortran, Fortran 95, however, much of the same concepts are the same in the later versions with a few advancements.

Overview

Names


When considering the naming practices in a language, three areas are of major concern to most programmers: length of variable/identifier names, reserved words, and case sensitivity of the language. These are all very basic concepts which are crucial to understanding a language. Throughout the years, Fortran has remained a simple language to learn and use, and the naming practices highlight this ease of use.

In the first versions of FORTRAN, variable names were limited to a length of six characters, however, the current standards allow variable names up to 31 characters in length. While this means that variables can be extremely exhaustive in their descriptiveness, it is convention to make variables just long enough to be meaningful to the reader.

Fortran 95 has an exhaustive list of keywords, with even more added in the 2003 and 2008 standard, however, there are no reserved words in Fortran [ScienceFortran]. This means that keywords such as INTEGER, REAL, DO, and PROGRAM are legal identifiers in Fortran, this however is extremely poor practice and most programmers are advised against using keywords as identifiers.

As with most programming languages, the names of identifiers in Fortran begin with a letter and are followed by any sequence of letters, numbers and/or underscores. Fortran is for the most part a case-insensitive language5, thus, there is no distinction made between the identifiers: Var and var. There is no convention of how to write Fortran identifiers, however, James Ortega writes, “It is common (but not universal) practice to write Fortran identifiers in capital letters” [ScienceFortran].


Bindings


Fortran is a strongly typed static language. This means that variable types in Fortran are bound before run-time and cannot be changed during the execution of the code. Storage allocation for arrays in Fortran 90 and beyond, however, can be handled dynamically with the use of the ALLOCATABLE statement.

Scope


The scope of variables in Fortran is static in nature and therefore determined by its position in the program’s structure. That being said, if a variable is declared in a function it is not visible outside of that function, unless there is a function nested within it, since Fortran allows nesting of functions. Local variables, variables which are declared locally in a program unit, will hide other “global” variables, variables declared above the program unit that are still visible to the unit.

Data Types


Fortran contains several data types for programmers to use in the design of their programs. There are five intrinsic data types supported by Fortran, these include: INTEGER, REAL, COMPLEX, LOGICAL, and CHARACTER data types. Each of these intrinsic data types can be enhanced using with a KIND. The KIND function allows the programmer to tell the compiler how the type should be internally represented, i.e. number of bytes for numerals. The example below is a variable declaration for REAL number, x, with twice the number of bytes as normal:

REAL (KIND=2) :: X = 10.25

There is a caveat with this functionality however, not every compiler follows the same numbering system, therefore it is advised to be cautious when using the KIND function and to check your compiler’s documentation before using this feature.

Notice in the above example the type of X is explicitly stated as being REAL, this is a major point to Fortran programming. Earlier versions did not have explicit typing, variables were typed according to their names, with variables

Beyond the intrinsic data types, Fortran 90 and beyond support derived types. The example of a derived type below is from An Introduction to Fortran 90 for Scientific Computing by James Ortega:

TYPE CAR


REAL :: WEIGHT

REAL :: LENGTH

INTEGER :: ID_NUMBER

END TYPE CAR [ScienceFortran]

Ortega states that these derived types can be loosely thought of as arrays, as each instance has several internal components. However, unlike arrays, these values have differing types, and are more akin to objects in some of the more traditional object-oriented programming languages, such as Java and C++. The differences between this and object-oriented programming in Fortran will be discussed in a later section.

Expressions and Assignment Statements


Fortran’s original design purpose was to make programming mathematical formulas easier than assembly programming. And the widespread use of Fortran even today in industry where mathematical computations are extremely prevalent or important speaks to Fortran’s success in this area. In Fortran 95 there are four categories of operators: arithmetic, relational, logical and character. The last operator category, character, includes only one operator and cannot be used with the arithmetic operators. The single character operator is the concatenation operator “//” and can be written as: CHARACTER :: STRING = STRING1 // STRING2. The arithmetic operators include the four basic operators from mathematics “+”, “-“, “*”, “/” as well as the exponentiation operator “**”. The relational operators include the arithmetic comparison operators such as: “==”, “/=”, “<”, “<=”, “>”, “>=”. Finally, Fortran supports the logical operators NOT, AND, OR, XOR, EQUIVALENT, and NOT EQUIVALENT written as: .NOT., .AND., .OR., .XOR., .EQV., and .NEQV. respectively. The operator precedence of Fortran can be summarized as follows:

  1. Exponentiation (**)

  2. Multiplication/Division (*, /)

  3. Addition/Subtraction (+, -)

  4. Relational operators (<, <=, >, >=, ==, /=)

  5. .NOT.

  6. .AND.

  7. .OR.

  8. .XOR., .EQV., .NEQV.

It is interesting to note that the unary versions of “+” and “-“ share the same level of precedence as the binary versions, thus making the negative unary operator at the lowest precedence of the arithmetic operators.

The associativity of operators in Fortran is for the most part left to right, as with most mathematical expressions. However, there are two exceptions to this, the exponentiation operator “**” and the logical .NOT. operator are both evaluated right to left.

Assignments in Fortran follow the standard mathematical writing conventions, which is to be expected as Fortran was designed to make programming mathematical and scientific formulas easier. The following example declares three REAL variables and sets the value of C to the sum of A and B:

REAL :: A, B, C

A = 10

B = 5


C = A + B

As can be seen this form of assignment is very similar to many modern programming languages, such as Java, C#, C++, and Ada. This assignment structure is very intuitive and easy to grasp, which may explain why it has remained largely unchanged even in the most modern of languages.


Statement-Level Control Structures


Fortran supports many control structures for selection and repetition statements. The selection statements in Fortran are the IF and SELECT statements for single and multiple selection respectively. In Fortran the IF statement follows the structure of IF-ELSE IF-ELSE-END IF, with the ELSE IF and ELSE statements being completely optional. The current standard uses logical and relational if statement conditions, as well as allowing the use of arithmetic conditionals. The arithmetic IF is currently labeled obsolescent and thus should be avoided in the vast majority of cases, and will not be discussed here. The multiple selection control structure in Fortran is very similar to the CASE statement in Ada. The CASE statement for Fortran takes a parameter to begin with and then executes statements based on the value of the parameter. An example of the Fortran SELECT CASE is shown below:

SELECT CASE (X)

CASE (VALUE1)

…. (statements for value1)

CASE (VALUE2)

…. (statements for value2)

END SELECT

The repetition statements of Fortran include the basic DO loop, a DO WHILE loop which takes a logical condition as a parameter, and a FORALL loop which was added in Fortran 95. The standard loop in Fortran is rather powerful, and is reminiscent of a for loop in other high level languages. The structure of the DO loop is as follows:

DO VARIABLE = INITIAL_VAL, END_VAL, STEP

As one can see the major components of a standard for loop are included in Fortran’s DO loop structure: an initial value, an ending value and an incremental step. The major difference between traditional for loops and Fortran’s DO loop is that there is no way to do reverse-counter-controlled looping. This is due to the fact that the initial value cannot be greater than the ending value, as the ending value is always evaluated as to whether it is less than the value of the variable parameter. Should the initial value be greater than the ending value, the loop will not execute.

The DO WHILE loop was added in Fortran 90 and allows a logical condition to be passed as a parameter and will loop until the condition is evaluated to false, much like the standard while loops of modern programming languages. One of the major features added in Fortran 95 is the FORALL looping construct. This loop construct is important in that it was developed to aid in the vectorization, iteration over a collection such as an array, and is necessary in later versions of Fortran which allow concurrent statements. Generally speaking, the FORALL construct is used in Fortran 95 as an assignment iterator over array indices, such as the example below:

FORALL (I = 1:100, J = 1:100) A(I,J) = I * (I + J)

This example will loop over every combination of the 100 x 100 array A and assign each index denoted by (I,J) to a value based on I and J. It is important to note that I and J in this context have statement scope and will hide any other I or J variables elsewhere in the program [IBMComp].

Subprograms


Fortran provides several forms of subprograms to aid programmers in process abstraction, hiding the low level details. These subprograms are known as functions, subroutines and modules. The basic subprogram for Fortran is the function, which takes in optional parameters to return a result back to the calling portion of the program. An important note is that the returned value takes the name of the function itself, for example, a function to compute the value of a factorial which is declared as:

FUNCTION FACTORIAL(N)

…..

END FUNCTION FACTORIAL



will return the factorial value by setting the resultant value to the variable FACTORIAL at the end of the function. Fortran also allows nesting of functions inside of other functions, as well as passing a function as a parameter of other subprograms.

Another type of subprogram available is the subroutine. The major difference in subroutines as opposed to functions is the number of values that can be returned by each type of subprogram. A function returns only one value to the calling program segment, whereas a subroutine “may return arbitrarily many values” [ScienceFortran]. For example, the following subroutine will effectively return three values to the calling program:

SUBROUTINE FUN (X, Y, Z)

IMPLICIT NONE

REAL, INTENT(INOUT) :: X, Y, Z

X = X / 2

Y = Y / 2

Z = Z / 2



END

The above subroutine takes in three real values, halves them and returns them to the calling program segment.



The final type of subprogram for Fortran is the module. A module can be thought of much like a package in Ada. Each module contains its own specifications, variables, functions and subroutines. These modules can then be imported into other programs, allowing the program which imported it to access all of the meat of the module. This could be useful, especially if there are functions which a programmer needs in multiple programs.

Object Oriented Programming


As noted earlier, there is some object oriented programming concepts in Fortran. The derived data types from Fortran 95 resemble objects in languages such as Java and C#. In Fortran 2003 these derived types allow for functions to be placed within the types, thus making the derived data types objects, however, as noted early on in this paper, Fortran 2003 may or may not be fully supported by all compilers so use of the object oriented concepts should be used cautiously.

Concurrency


The only concurrency for Fortran is in the 2008 standard. The 2008 standard includes support for DO CONCURRENT looping construct which allows for parallelization of loops where the implementations are independent of each iteration. As stated before, though, the lack of compiler support for the 2008 standard can effectively nullify the support of concurrency for Fortran, outside of specific circumstances.

Exception Handling


One of the major areas of modern programming languages where Fortran falls behind is the inclusion of exception handling. There is no exception handling within Fortran other than programmer checks using IF statements to bypass certain points of code where issues may arise.

Evaluation


The evaluation of Fortran as the conclusion to this paper will be summarized in respect to four criteria: Readability, Writability, Reliability and Cost. These criteria are consistent with Robert Sebesta’s concepts on what make a language effective or not [Seb12]. This section will largely be the opinion of the author of this paper, and as such should not be taken as hard fact as the definitive effectiveness of the language as a whole.

Readability


The overall structure of Fortran and the intuitive design of the expressions as well as assignment statements make Fortran a very easy language to read and understand. The overall design of Fortran is very procedural and thus lends itself excellently to the fields of which it was intended to be used for, specifically those focusing on mathematical operations. These features in addition with language conventions and the free form of the new versions since Fortran 90 make Fortran exceptionally easy to read and understand, even for those unfamiliar with the semantics of the language.

Writability


The ease of reading Fortran makes its writability all the better. Fortran is one of the best languages to write programs which are heavy in mathematical computations, due to the commonality between the syntax of the language and mathematical expressions. Another benefit to the writability of Fortran is the limited number of control and looping constructs. The smaller number of structures makes the knowledge of the available constructs that much larger, thus leading to more understandable code which is easier to read. Yet another benefit for Fortran is the large amount of intrinsic operations for mathematical operations, thus abstracting the finer details, such as the intrinsic operations for complex data types for example. All of these features make Fortran an extremely useful and easy to learn language.

Reliability


The reliability of Fortran can be summed up by a quote from Turing award winner Tony Hoare, “I don't know what the language of the year 2000 will look like, but I know it will be called Fortran” [Lee14]. According to an article by Lee Phillips in Ars Technica, most of the production code involved in today’s cutting edge research is still done in Fortran code. This would not be possible almost 60 years after the original development of FORTRAN if the language was not extremely reliable in its purpose. In fact some of the things which make Fortran a giant in the programming world are the same reasons that other, newer languages can tout as the reasons for their success. Fortran’s strong typing and static binding are some of the reasons it is so good at what it does. The strong typing and static binding help to eliminate errors that can occur at run-time, thus decreasing development time for applications. More so, the readability and writability of Fortran increase its reliability by several orders of magnitude. The ease of reading and writing the language mean that upkeep, maintenance, and modification of existing applications is quick and relatively simple. These features as well as the simple fact that Fortran is still in use today in such systems as weather prediction models and calculation of extremely difficult and theoretical mathematical values in physics are a testament to the reliability of Fortran [Lee14].

Cost


The cost of Fortran can be considered minimal at best. Compared to the cost to learn and use languages of comparable age, Fortran is extremely cheap. As seen from the readability, writability, and reliability, Fortran costs very little to learn and maintain. The advancement in compilers and IDEs have led to compilers, which are available for free for the development of Fortran code, some even providing the ability to program in even older versions of Fortran such as FORTRAN 77.

All of the information provided shows just how effective and useful Fortran still is to the programming world. While it may be an older language and may not include everything that some of the more modern languages innately provide (pure object oriented programming, concurrency, exception handling, etc.) the language has remained largely the same, and still does the one thing that it was originally meant to do extremely well: mathematical computation. It is this author’s opinion that despite its age, Fortran will continue to remain a large part of technological advancement for many years to come. Fortran has evolved much over its lifespan and shows no sign of slowing down soon, with a new standard in review for 2015.


Bibliography


For14: , (Fortran),

Seb12: , (Sebesta),

Ber07: , (Bergstein),

Seb12: , (Sebesta),

Seb12: , (Sebesta 43),

Seb12: , (Sebesta 44),

Seb12: , (Sebesta 45),

ForStat03: , (Fortran 2003 status),

ForStat08: , (Fortran 2008 status),

ScienceFortran: , (Ortega),

IBMComp: , (IBM Compilers),

Lee14: , (Phillips),




Fortran



1 Fortran versions which pre-date Fortran 90 were conventionally spelled in all-caps [For14]

2 The first compiled language system was developed by Laning and Zierler at MIT as early as the summer of 1952, however, the language and system never left MIT. [Seb12]

3 The status of current compiler support for Fortran 2003 can be found at: http://fortranwiki.org/fortran/show/Fortran+2003+status[ForStat03]

4 The status of current compiler support for Fortran 2008 can be found at: http://fortranwiki.org/fortran/show/Fortran+2008+status [ForStat08]

5 Strings in Fortran are case-sensitive.


Download 41.77 Kb.

Share with your friends:




The database is protected by copyright ©ininet.org 2024
send message

    Main page