Using the F Programming Language in the Classroom

Bob Hancock

Professor, Engineering & Math
Orange Coast College
Costa Mesa, California, USA

1997 November

I've been teaching a beginning programming course (at a 2 year college) in scientific programming, using the F language, for almost a year. This particular course had a long history of FORTRAN IV, APL, ADA, and FORTRAN 77. Since I was starting out new with the course, I decided to look around to see which compilers were available, using Fortran 90.

I quickly settled on F. If I had used a more complete Fortran 90 compiler, I would have had to make hundreds of decisions about which was the best method to write code. Fortran 90 is a huge language, with the possibility that the same procedure could be written a number of different ways (all following slightly different syntax rules). But the designers of F have already made most of those decisions for me. There is generally only one way to do certain tasks (such as opening an external file, writing a function, or defining an array). The syntax rules of F are strict, but they produce efficient and easy-to-read code--plus it will run under any big-time Fortran 90 compiler.

I'd decided I wanted to use Fortran because it is still one of the easiest programs to teach, and yet provides the science or engineering student with a skill that will be of immediate usefulness when he or she gets that first job. Most scientists or engineers do not take a lot of programming coursework; they need to be able to write useful, number-crunching code, as quickly as possible.

I've been using Windows 95 version of F. It comes with an editing and run-time shell, presently called F_World. It has a simple text editor, from which Modules can be validated (syntax checked), and from which main programs can be run. Syntax errors are identified, pointed to, and usually explained correctly. There is still the good old ``Syntax Error''--but at least it is pointing to the wayward line. The overall process is fast enough that I can usually ``take a guess'' when I'm not sure of my code, and let the compiler tell me what my mistake was. This is often much faster than looking it up in a book.

The compiling process moves directly from source code to a running program. The ``compile-link-run'' steps are all automatic. And the system has been extremely stable; it has never crashed my Windows 95 system. Exception errors are well handled, returning you back to the F_World shell.

This interactive environment has been especially helpful for the students. They're able to concentrate on writing algorithms--not on learning how to master computer hardware or the operating system. Many of my students have had no previous computer experience, but are able to write effective programs in about 4 to 5 weeks. By the end of the semester, they will have written more than 20 required programs.

Students with home computers often purchase their own copy of F at a reasonable price. I allow students to write their code on whatever computer they desire; I then require them to turn in a printout of their source code plus a copy of the source code on a floppy disk. I randomly run some of their source codes on my office computer. I get rapid verification that their program will work, and they get rapid feedback of my evaluation.

I think F (and Fortran 90) is nicely positioned in the modern programming world. Engineers and scientists can write fairly simple, straight-forward, structured programs, without jumping into full-blown object-oriented programming or graphical-user interfaces. But, F is completely capable of handling modern procedural constructs: dynamic allocation of memory, recursive functions, pointers, generic procedures, overloaded operators, and user-defined data types (and operators). The pointers in F are much safer to work with than in the C language. At the other end of the spectrum (since F is derived from classical Fortran), I find that the students can usually look at older FORTRAN 77 code and figure out what a simple algorithm is doing. I spend just one day at the end of the course covering F77.


Textbooks are still a bit of a problem. The first semester I used well-written Fortran 90 book, trying to tailor it to the F language--this was book #1 (below). It required a lot of extra ``handouts'' to students, showing code segments re-written for F. This book is an excellent introduction to scientific programming for the beginning student, but it is hard trying to adapt it to the strict F syntax.

I am currently using "Programmer's Guide to F" (book #2). The code is obviously correct and well written, but I don't find the overall layout ideal for a beginning student. Technical terms are often used before they are defined. The end-of-chapter problems are interesting, but not enough of them exist in various areas. This would be an excellent book for a FORTRAN 77 programmer desiring to upgrade his or her skills.

I've looked-over "essential Fortran" (book #3). It uses syntax rules that will work in both F, and in Lahey's ELF90 compiler (or in any complete Fortran 90 compiler). It seems to be fairly thorough, but the examples will jump suddenly from the simple, to the complex. I had a hard time understanding some of the harder examples (which wasn't a problem with books #1 or #2). I should probably look it over more closely.

Book #1: Fortran 90 Programming, by Ellis, Philips, & Lahey, Addison-Wesley, 1994

Book #2: Programmer's Guide to F, by Brainerd, Goldberg, & Adams, Unicomp, 1996

Book #3: essential Fortran 90 & 95, by Meissner, Unicomp, 1997

My students and I have enjoyed programming with F for the last year. I highly recommend F to anyone that is just beginning with Fortran, or for experienced programmers who desire to update their skills from an earlier version of Fortran.

For anyone with further questions about my experiences with the language (or the textbooks), I'll be happy to respond to email questions.