Error Messages in the F Programming Language


David Epstein
Imagine1, Inc.
david@imagine1.com

Introduction

This is the story of my first programming error. A large part of my drive while creating the F programming language and F products possibly originates from this experience.

As I entered the basement of Evans Hall on the UC Berkeley campus, I scoffed at the warning painted on the wall

Abandon all hope,
you are now entering
  THE PIT

``Not me'', I said in my head. I was sure that this first programming assignment for CS1, Introduction to Fortran, would be a one or two hour breeze--instead, seeds of the F programming language were planted. Eight hours later, 10 pm, I gave up and headed back to the dorm hungry and mentally exhausted.

The Input and Output

Here are the essential pieces of that dreaded program which had been ``punched in'', dropped on the floor twice, and handed to the card reader numerous times. I had no technical training for the result of my program--``Unknown Statement''

      PROGRAM FIRST
C MY FIRST PROGRAM
      REAL MPOS, CATPOS, CHEESE
      INTGER I
C READ IN THE MOUSE, CAT AND CHEESE POSITION
      PRINT *, 'ENTER POSITION OF MOUSE'
      READ *, MPOS
C etc...

Maybe if the text book or the professor discussed error messages before this first assignment, I would indeed had made a quick exit from THE PIT. I suppose, however, that the discussion of

  1. how to enter a program onto punch cards
  2. how to run a program
  3. how to get a print out of a program
  4. where to turn in a print out of a program
  5. what the problem is that the first program was to solve, as well as
  6. programming concepts, semantics and syntax

did not leave enough time for the professor to give us a preview of the ever important and inevitable decyphering of cryptic error messages. [Maybe there was a preview of error messages during the 3 hours of lecture that preceded the first assignment. If there was, that particular aspect overflowed right out of my ears.]

In case you did not catch my error, this is probably what was handed to me on a piece of paper, but I had no idea what the error message meant even if it was actually presented in the below meaningful location.

      PROGRAM FIRST
C MY FIRST PROGRAM
      REAL MPOS, CATPOS, CHEESE
      INTGER I
***"Unknown Statement"
C READ IN THE MOUSE, CAT AND CHEESE POSITION

Quite Simple Actually

I tracked down a student that passed CS1 the previous quarter and handed him my program. Three hours later, he explained to me that I misspelled the word INTEGER. I couldn't believe it!

A 20 minute walk to THE PIT, 20 minute wait for a card punch, 20 minutes to punch a new card and run the program and turn in the assignment and I had successfully completed my first of many programs. Decades later, my latest computer program is an F compiler.

F vs. Fortran 90

While writing a Fortran 90 compiler for a large hardware vendor, I could not believe that my teammate, one of the worlds front-end and error-recovery experts, was unable to produce accurate error messages when a single character was missing. He explained that since the word INTEGER is not reserved, it would be difficult and possibly inaccurate to report that it was misspelled. In addition, insignificant blanks and implicit declarations make accurate error reporting nearly impossible in many situations. For example

     INTEGER INTEGER
     INTEGER INTGER
     INTEGER I
     INTGER  I
     INTGER  I J K = 3

I would expect your favorite Fortran 90 compiler to do little more than report ``syntax error'' or ``unrecognized statement'' and give a line number for the fourth line (and the fifth line in free source form.)

Only One Chance

Often, if something does not work the first time I try it, it goes into the trash can or is placed down onto a stack and is never revisited. This was my experience with a popular C++ environment. It presented me with over 20 buttons, each button containing a picture that gives a clue as to what happens when it is clicked. I skipped the buttons and went with the sure shot of changing some code by hand. I changed the name of the window displayed in the sample program.

It never linked! The 700+ pages of on-line documentation did not help me within 1 hour. I said goodbye to C++ and started programming in Fortran 90. [3 years earlier I had tried to convince my Fortran 90 compiler team to program in C++ instead of C. Thus, I have given both the C++ language and a C++ environment a chance, at two different times, spanning the years 1991 to 1994.]

The Influence on F

One design goal of F is to be an ideal first programming language as well as a powerful professional language. This means that F works the very first time it is attempted as well as the one thousandth time. In the design of F, the powerful professional language was simply achieved through the functionality of Fortran 90. Since many features in Fortran 90 can be done one of two (or three or four!) ways, the difficult part of designing the F programming language was deciding which one specific way best fit into the F strategy. For example, the following Fortran 90 examples assign the value of 3 to an integer I:

 (1) INTEGER I
     I = 3

 (2) INTEGER :: I
     I = 3

 (3) I = 3

 (4) integer :: I
     i = 3

Not shown above are many of the permutation for spelling the word INTEGER:

 Integer, INteger, InTeger, IntEger, inTEGer, etc.

as well the infinite ``fixed source form'' versions:

 I N T E GER, inteGE R,   int     EGER, etc.

In F, there is only one way to code the above example of assigning the value of 3 to an integer ``I'':

     integer :: I
     I = 3

Note that the second appearance of ``I'' is capitalized!

Freedom's Just Another Word

Whereas it may be viewed as freedom to have an infinite number of ways to assign the value of 3 to an integer I, one idea of F is that it is freedom to have only one way to assign the value of 3 to an integer I.

The freedom results from

The best example I have of the freedom that results from a concise language is the explanation of why the word ``dimension'' is required when declaring an array in F.

   real, dimension(1,2,3) :: arr1 ! valid Fortran 90 and valid F
   real :: arr2(1,2,3)            ! valid Fortran 90 but NOT valid F

One day while debugging the F compiler (which is written in F), I needed to find all the array declarations. I simply searched for the word ``dimension''. My ``grep'' tool wrote all the lines containing the word ``dimension'' into a file. Viola!

The decision between

   real, dimension(1,2,3) :: arr1

and

   real :: arr2(1,2,3)

was actually made many months before and was driven by the consistency with the len= and kind= both appearing before the double colon, as in

   character(len=3), dimension(4) :: ch_arr

The moment I realized how simple it was to find all the arrays in the F compiler, the decision for the word ``dimension'' paid off.

Revising Some Decisions

The first F language required keywords to be in upper case letters instead of lower case letters. Following this rule, however, resulted in slow input of F code and some arthritis on the left pinky shift motion. After switching to lower case keywords, F coding returned to the same input speed as C coding (C requires lower case keywords.)

Rules for Intger

Here are some of the rules in F that differ from Fortran 90 that requires the below code for assigning a value of 3 to I
     integer :: I
     I = 3

F rules:

Every F Program is a Fortran Program

For those that are hearing about F for the first time, it may appear that the above rules make F and Fortran quite different. F is both different than Fortran and the same as Fortran. F is different than Fortran because it imposes many rules that restrict the many options available in Fortran. F is the same as Fortran because it is a pure subset of Fortran 90. Every F program a Fortran 90 program. Every F program will run through a Fortran 90 compiler. It is possible that somebody who has never heard of F is writing F code and using a Fortran 90 compiler.

Try It

The F compilers are able to tell a programmer that ``intger'' is a misspelling of the word ``integer''. This is extremely nice for the beginning programmer, and possibly only a small convenience for a professional programmer.

It could be that F is the only programming language in the world that is able to help the introductory student with spelling. I assume other languages do not prevent a compiler from accurately reporting a misspelled keyword, but I have not seen this feature in any existing language product, even Pascal products.

Contacts

Those interested in discussing this aspect of language design, and the F language in general can subscribe to the F email interest group. Send an e-mail message to f-interest-group-request@imagine1.com with the word ``subscribe'' as the body of the message.

The Imagine1 web page is

     http://www.imagine1.com/imagine1/

Click here to read the second part of this article.