Defining the obvious - FORTRAN Example

As I have explained when talking about the advantages of denormalisation I believe that it is frequently neccessary to state the obvious, since different people have different views of the obvious, coloured by language, culture, experience etc. The following example dates back to my experience many years ago using FORTRAN.

In FORTRAN one opens a file on a numbered logical unit, i.e. the caller specifies the unit. Compare this to e.g. UNIX/C where one opens a file and the system returns the unit (a file descriptor). I wanted to to write a library routine that would find an available unit number.

Now the FORTRAN standard helped me out a little on this but unfortunately it also blind-sided me. I don't have the standard available so I can't quote this verbatim but the following is what I remember.

  1. One can "INQUIRE" about a unit that "exists"; it can tell you if the units is "in use".
  2. One can "INQUIRE" about a unit that does not "exist"; it will tell you that the unit doesn't exist.
  3. One can "OPEN" a file on a unit that "exists" and "is not in use".

It was obvious to me at the time that the converse is that you cannot open a file on a unit that doesn't exist. I wrote the library routine based on that. Everything was fine until I changed compiler and then it fell apart. Why? It's obvious in hindsight.

The second compiler took the philosophy that units were scarce resources and so the logical unit only came into existance when a file was opened on it; the compiler assumed that it was valid to open a file on a unit that did not exist.

That's one reason I like the C standard's habit of defining what is explicitly system-dependant. (Of course I wish there were less system-dependant features but we can't have everything.)

I also have an example from the UNIX world, which is much more pedantic.

Back to Bill's home page