a review of approaches to teaching fortran

3

Click here to load reader

Upload: daniel-w

Post on 23-Sep-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: A Review of Approaches to Teaching Fortran

IEEE TRANSACTIONS ON EDUCATION, VOL. E-22, NO. 1, FEBRUARY 1979

A Review of Approaches to Teaching Fortran

DANIEL W. LEWIS

Abstract-Fortran continues to be taught as a first programming lan-guage in many engineering curriculums. Two teaching approaches arepredominant: the conventional approach and the preprocessor ap-proach. The latter introduces the concepts of structured programmingby using an augmented version of Fortran which is translated into stan-dard Fortran IV by a special preprocessor program. A third approachhas been successfully used at the University of Santa Clara. It empha-sizes the inherent block structure of the subprogram facility of standardFortran as the key to top-down program implementation.

INTRODUCTION

Fortran is the oldest high-level programming language. Itcame into existence long before programming style (cf., [ 1 )was even a twinkle in Dijkstra's eye, and not unexpectedly,it contains many features that, when abused, can lead to un-structured and obscure programs. Most computer scientistsprefer other languages such as Algol or Pascal that offer feweropportunities for abuse, but for all its faults, Fortran contin-ues to thrive. One of the reasons for its continued use is theseemingly inextricable relationship between it and engineering.Thus there have been many attempts to modify Fortran sothat the relatively new principles of good programming tech-niques can be taught within the context of an unyieldingengineering environment. Many universities use a preprocessorthat allows students to write their programs in a superset ofFortran statements which supports the well-known IF-THEN-ELSE and WHILE-DO structures. This paper presents anotherapproach developed around the inherent block structure ofthe Fortran subprogram facility as a means of managing pro-gram complexity [2] . Consequently, subprograms are intro-duced very early in the course, contrary to frequent practice.The students are typically freshmen from science and engi-

neering with a mathematics background limited to algebra.The course is their first introduction to computers.

THE GOALS OF A FIRST COURSE IN PROGRAMMING

A first course in programming must introduce a studentto the components of a computer system, the principles ofcompilation versus execution, and the syntax and semanticsof the particular language. Beyond that, such a course shouldalso teach a programming methodology that not only is usefulas a problem-solving technique, but which minimizes both syn-tax and logical errors, and makes programs easier to under-stand. The latter is referred to as program clarity (or trans-parency), and is perhaps the most important single item thatcan reduce a student's difficulty in initially programming anassignment and then debugging it.Problem-solving techniques should (1) provide the student

with an idea of how to initially define his program in terms ofits expected input and output data, (2) how to devise algo-rithms with which to implement the program, and (3) how toproceed with the task of implementing the algorithms as acomputer program. Although the first two parts of problemsolving have been addressed in the same manner for manyyears, the process of algorithm implementation has been thetopic of much discussion within the computer science com-

Manuscript received March 31, 1978;revised July 24, 1978.The author is with the Department of Electrical Engineering and

Computer Science, University of Santa Clara, Santa Clara, CA 95053.

munity. The three approaches to teaching Fortran discussedhere essentially reflect variations on this theme.The student should be strongly encouraged to develop habits

that minimize both logical and syntactical errors. Thus certainfeatures of a language should be used instead of others, such asthe logical IF as opposed to the arithmetic IF statement, orthe computed GO TO rather than the assigned GO TO state-ment. When the student has a choice of statements or ways inwhich to construct the same statement, he should be taughtto be consistent and to select the feature that is most appro-priate within the context of its application. For example, heshould use a logical IF for decision, a computed GO TO forselection, and a DO statement for iteration.The concepts of psychological set and distance are of pri-

mary importance to this philosophy. Psychological set is thehuman tendency to react in an expected way to a certainstimulus. With a programming language, this may be exem-plified by our expectation that a variable called SSNUM Willcontain a social security number, or that a subroutine calledSORT will arrange an array into a particular order. A morerelevant example is that we have a psychological set estab-lished in calculus that causes us to expect a function to nevermodify its arguments. New psychological sets can be estab-lished through repetition. If they are consistently observed,they can make the content and meaning of a program moreapparent at first glance.The second concept is that of psychological distance. This

has to do with the human ability to distinguish between twoitems. The simplest example would be our difficulty in dis-tinguishing between two variables named NMCRDS andNUMCRD, or names such as IJK, KJI, and JKI. However, theprinciple may also be used as an argument against the use ofstatements such as the assigned GO TO which is similar inappearance to the computed GO TO and offers no particularadvantage over it. Since the use of an EQUIVALENCE state-ment (or the unrestricted use of COMMON) can create aliasesfor variable names that defeat the intent of psychologicaldistance, their use would also be discouraged.

Finally, the student should be taught to construct his pro-gram in a manner which is the clearest representation of thealgorithm it implements. At times this may be inconsistentwith program efficiency, but the point becomes a moot onewithin the context of a first course in programming. Therecent work in structured programming and the top-downapproach have provided us with much that can aid in realizingthis goal.

THE CONVENTIONAL APPROACH

The older textbooks (and some of the recent ones) [3, 4, 5]for a first course in Fortran make extensive use of flowchartsas a programming tool. Each new Fortran control statementis explained in terms of equivalent flowchart symbols. Asthese statements are mastered, they are combined with othersto form simple programs. The flowchart technique then pro-vides a visual image of the organization of the total program.Unfortunately, there are several drawbacks to using flow-

charts. A beginning student is immediately convinced of theirvalue since they do enhance the visual perception of a pro-gram's organization. But the student quickly learns the limi-tations of their usefulness as the complexity of his programsgraduates from the realm of small classroom examples to largepractical industrial programs. Flowcharts simply do not pro-vide a solution to managing complexity, but only serve to de-lay the point at which the complexity becomes unmanageable.Other than the arithmetic IF statement, Fortran control

statements can only be flowcharted as a combination of primi-

0018-9359/79/0200-0023$00.75 C 1979 IEEE

23

Page 2: A Review of Approaches to Teaching Fortran

IEEE TRANSACTIONS ON EDUCATION, VOL. E-22, NO. 1, FEBRUARY 1979

tive flowchart symbols. For example, there is no primitiverepresentation of either a DO statement or a computed GO TO.As a result, a student who first flowcharts his problem, thenconverts the flowchart into Fortran, usually creates programswith very few DO statements or computed GO TO'S. Instead,the final programs tend to contain many arithmetic IF and un-conditional GO TO statements with attendant program dis-continuities. Consequently there are many labels and confus-ing back-references.Another problem with the conventional approach is that

Fortran subprograms are one of the last subjects to be pres-sented. They are considered as an advanced feature that al-lows a frequently repeated segment of code to be replacedby references to a single subprogram. Although subprogramsare usually noted to also be a means of modularizing a pro-gram, it is still after the fact and within the context of aflowchart-driven implementation. As shown in the last ap-proach discussed, the subprogram facility can be the key toprogram clarity.

THE PREPROCESSOR APPROACH

A few of the more recent textbooks have been written foruse in a course that teaches an augmented version of Fortranwhich includes the well-known IF-THEN-ELSE and WHILE-DOstructures [6, 7, 8, 91. The students prepare their programs inthis pseudo-Fortran and then use a special program called apreprocessor that translates their programs into standardFortran. The philosophy of the approach is twofold:(1) It reduces the number of control structures that the

student must learn in order to write his first useful program.This is due to the fact that any program can be written interms of these two constructs and concatenation (sequence)[10].(2) The introduction of the IF-THEN-ELSE statement allows

a restricted form of block structure that the preprocessor can(but usually does not) use to monitor the scope of variables.Preprocessors usually also cover shortcomings of the Fortrancompiler, such as issuing warnings about mixed mode expres-sions.The preprocessor approach usually drops flowcharts in favor

of the more popular practice of using the IF-THEN-ELSE andWHILE-DO structures to support a top-down program refine-ment process of algorithm implementation. This process canbe quite effective in producing well-organized programs. Sinceit does not require the use of the subprograms, they are usu-ally taught as one of the last subjects in the course. Conse-quently, student programs frequently turn out as one longmain program spread over several pages of a program listing.Even if this program is well-organized, the student can exper-ience difficulty in grasping the entire semantic meaning of thismany statements at once, and so program transparency suffers.A practical problem with the preprocessor approach is that

the student is taught a programming language which he quiteprobably will not be able to find after graduation. Althoughthe new (1976) Fortran standard may alleviate this paradox,until it is more widely utilized, the graduate must either pre-process his programs by hand or (more likely) abandon theapproach and learn to use the unaugmented version of Fortran.

THE ToP-DOWN APPROACH USING STANDARDFORTRAN IV

The course to be described is taught as a one-quarter courseover a ten week period with four one-hour lectures and an in-formal three-hour programming laboratory each week. Thereare six one-week programming assignments and one two-weekproject at the end of the term.Proponents of the preprocessor approach would argue that

they are also using top-down programming techniques. This istrue, but top-down programming can be successfully accom-

plished without the IF-THEN-ELSE and WHILE-DO structures.These structures might be more accurately described as arti-facts of structured programming. Top-down may be describedas the step-wise process of implementing a program by resolv-ing only the most immediate of the remaining unresolveddetails of the program at each step, while leaving the rest to beresolved in later steps. As such, it is a refinement process thatworks from the outside in, postponing the implementation ofdetails as long as possible. A clear understanding of this con-cept separates top-down programming from dependence onany particular type of control structure such as the IF-THEN-ELSE.Fortran subprograms inherently provide a facility for this

top-down approach. As the student writes the main program,he will resolve only the most immediate detail of the totalprogram (such as the inputting of data and the outputting ofresults) and not worry about the details of how those resultsare computed. This particular responsibility is delegated to asubroutine yet to be implemented, and the main programmay thus be completed by the insertion of a subroutine callwith the appropriate input and output arguments. This ap-proach is then recursively applied to the implementation ofthat subroutine and those that it invokes, so that the com-pleted program exists as a main program and several sub-programs, each corresponding to a level of detail.Each level (main program, subroutine, or function) should

contain only those control statements as necessary to resolvethe single detail assigned to that level. Thus each level willusually contain less than twenty Fortran statements. Theresulting simplicity causes the purpose of each level to be al-most obvious.Since the subprograms are compiled separately, the student

does not have to worry about what variable names and state-ment labels he may already have chosen in previous levels. Hemay forget those levels completely, and since he also doesn'tneed to worry about how the remaining levels are to be im-plemented, his attention may be focused on a very small pieceof code. This isolation provided by the subroutines also placesa rather strict control on the scope of variables. Global effectsare restricted to be between two communicating levels andlimited by number of arguments passed. (The use of COMMONwould defeat this control, and thus is not discussed until theend of the course).This approach considers the subprogram facility as the most

important Fortran feature that can help a beginning student,rather than an advanced feature to be put-off until the end ofthe course. Accordingly, main program/subprogram structuresare discussed very early, long before the presentation of theDO, IF, or GO TO statements. The first programming assign-ments are thus examples of straight-line programming, empha-sizing the concepts of parameter passing and the notion of asubprogram as a process with a set of input data, a set of out-put data, and a task to perform.The basic control statements are then introduced. Each is

emphasized as having a particular application: the logical IFfor decision, the DO for repetition, the computed GO TO forselection, and of course the unconditional GO TO for transfer.The student is taught to recognize and distinguish situationsin which decision, repetition, and selection are required, andto select the corresponding control statement. This estab-lishes useful psychological sets which flowchart-derived pro-grams do not usually possess.

GUIDELINES THAT ENHANCE TRANSPARENCYThe reduction and control of complexity provided by the

top-down approach should be supported by a programmingstyle within each level. Such a style is concerned with the useof blank comment cards, indentation, and certain learnedpsychological sets to help suggest the semantic content of the

24

Page 3: A Review of Approaches to Teaching Fortran

IEEE TRANSACTIONS ON EDUCATION, VOL. E-22, NO. 1, FEBRUARY 1979

code. This enhances readability, clarity, and transparency.Several guidelines have been published [ 1, 11, 1 21 that satisfythis need.

CONCLUSIONSThe early introduction of subprograms as the vehicle for top-

down program design has been used as the basis of a freshmancourse in Fortran IV. This approach has successfully elimi-nated many of the usual programming problems that beginningstudents encounter, making it easier to understand and thusdebug their own programs. The approach not only simplifiesthe original programming task, but restricts the effects of er-rors so that isolation of bugs becomes trivial.Although not syntactically necessary, the style imposed by

the discipline of the guidelines encourages the production ofclear and correct programs. Constructs not recommended areexplained at the end of the course.As compared to the preprocessor approach, the top-down

approach does not require an augmented version of Fortran.Thus the student does not have to retrain himself after gradua-tion, nor hand-convert from the extended language to stan-dard Fortran. Moreover, the separate compilation of sub-routines provides a better control on the scope of variables(and the need for new variable names) than the weak blockstructure provided by a preprocessor.

REFERENCES

[1] B. W. Kernighan and P. J. Plauger, The Elements ofProgrammingStyle, (2nd ed.), McGraw-Hill, 1978.

[2] D. W. Lewis, "Block Structure and the FORTRAN Subprogram facil-ity," (unpublished).

[31 L. Cooper and M. Smith, Standard FORTRAN: A Problem-SolvingApproach, Houghton Mifflin, 1973.

[41 D. D. Spencer, Problem-Solving with FORTRAN, Prentice-Hall,1977.

[51 R. Didday and R. Page, FORTRAN for Humans, (2nd ed.),West, 1977.

[61 M. J. Merchant, Applied FORTRAN Programming with StandardFORTRAN, WATFOR, WATFIV, and Structured WA TFIV,Wadsworth, 1977.

[7] F. L. Friedman and E. B. Koffman, Problem Solving and Struc-tured Programming in FORTRAN, Addison-Wesley, 1977.

[8] J. K. Hughes and J. I. Michtom, A Structured Approach to Pro-gramming, Prentice-Hall, 1977, pp. 163-190.

[9] T. Tenny, "Structured Programming in FORTRAN", Datama-tion, July 1974.

[101 C. Bohn and G. Jacopini, "Flow Diagrams, Turing Machines, andLanguages with only Two Formation Rules," CACM, vol. 9, no. 3(May 1966), pp. 366-371.

[11] H. F. Ledgard, Programming Proverbs for FORTRANProgram-mers, Hayden, 1975.

[121 M. Boyl, A Guide for Programmers, Prentice-Hall, 197 8.

Correspondence

An Algebraic-Recursive Algorithm for Partial FractionExpansion with Multiple Poles

SHLOMO KARNI AND DELORES M. ETTER

Abstract-A new method for partial fraction expansion with multiplepoles is described, with its algorithm implementation. This method,unlike the classical one, does not require successive differentiations ofrational functions. It is purely algebraic and, furthermore, recursiveand simple.

INTRODUCTIONIn many cases, the need arises to expand a proper rational

function H(s) with multiple poles into partial fractions. Theprogram described here will accept any finite number of polesof multiplicity bounded only by the DIMENSION statement,with the one restriction that the numerator polynomial is oforder less than the total number of distinct poles.The classical method [1] requires differentiation of H(s).

Computer programs involving such differentiations. or limitedcases, have been published [ 21, [ 31.The present method, by contrast, does not require any dif-

Manuscript received May 25, 1978; revised August 21, 1978.The authors are with the Department of Electrical Engineering and

Computer Science, University of New Mexico, Albuquerque, NM 87131.

ferentiations. It's algebraic and recursive, thus offering asimple and an effortless solution. It is a modified version ofthe one described in [41, and is described briefly below witha flow chart (Fig. 1) and a program listing (Fig. 2).

DESCRIPTION OF METHODBy way of an example, consider a proper rational function

H(s), separated into A(s) and B(s), as follows

H(s) =~ F(s)

(s + pi)(s + P2)2 (s + p3)3F(s) I, 1

[(s + p)(s +P2(s+P3)][(S +P2)(s +P3)2]J

A(s) B(s)If degree H(s) < # distinct poles (3 in this case), then A(s)

is also a proper rational function. It can be easily expanded,yielding

[ Ks K2 K3 ]+ 1+(s + P0 (s + P2) (5 + P3) .(s + P2)(S + P32

C(s)

(1)

:2)

B(s)

where the residues K1, K2, K3, are called here "first-order"constants.

0018-9359/79/0200-0025$00.75 i 1979 IEEE

25