“GOD IS REAL, unless declared INTEGER.” That’s the only Fortran joke I know, the basis of which is one of the oldest (mis)features in the language, implicit typing. As it has been since The FORTRAN Automatic Coding System for the IBM 704 (1956), variables whose names start with the letters I through N are implicitly
INTEGER, all others are implicitly
REAL. (In ur-Fortran, these were called “fixed point” and “floating point”.) The earliest Fortran didn’t have type declarations at all, nor the
IMPLICIT statement. I think it safe to say that no other Fortran feature has caused programmers more trouble, yet it remains a “first-class” feature today. Some people want to change that, though the approaches vary. Let’s explore.
The original Fortran went even further regarding inferring attributes from names. Functions had names of four to seven characters, ending with the letter F, and if they were integer (fixed point) functions, the names started with the letter X; thankfully, that went away with FORTRAN 66. But while other ancient features such as fixed-form source and
EQUIVALENCE have been declared obsolescent, default implicit typing is still with us. For decades, programmers relied on implicit typing, saving them from having to explicitly declare their variables and function return types. For those same decades, other programmers got tripped up when, unawares, they created an integer-valued function with a name starting with, say R, and took advantage of another Fortran (mis)feature, implicit interface. Over the years, the language added
IMPLICIT NONE (first formalized in MIL-STD-1753) to force programmers to declare types, and now there is
IMPLICIT NONE (EXTERNAL), blocking implicit interfaces, but these “blade guards” must be explicitly (!) added by the programmer (or in many cases, forced on by a compiler switch.) Wouldn’t it be better if default implicit typing went away entirely? That’s a proposal put forward in Fortran Proposals – Eliminate implicit typing) (This site collects suggestions for future language features, where they can be discussed by anyone interested. It isn’t sponsored by the Fortran standards committee, but we will use it as one of many sources in our planning for future revisions.)
Both in Fortran Proposals and in Fortran Discourse) (a more general place to discuss Fortran) I have argued that simply dropping a decades-old feature is not “the Fortran way”. I suggested instead that default implicit typing, and maybe the
IMPLICIT statement (not
IMPLICIT NONE) be declared obsolescent, the way fixed-form source is already. What this would do is 1) stop (or at least slow) implicit typing from being taught as a language feature, 2) cause compilers to issue diagnostics if the feature were used (may require the user to ask for such diagnostics), and thus 3) discourage its use in new code. Once deemed obsolescent, it could be deleted from a later revision, but we rarely delete features, given that compilers will continue to support them anyway, and, speaking for myself only, I am against deleting features as that means you no longer have text in the standard explaining how the feature works with the rest of the language.
An objection to making implicit typing obsolescent is that it doesn’t require compilers to flag such usage by default, only that the capability be there (usually via a compiler option checking for standards compliance.) My counter to that is that the first thing most programmers would do is turn off this feature, and if they couldn’t, they’d use a different compiler. Another suggestion adds a third category for “retired” features, presumably with default reporting, but this seems to me to be an unnecessary complication.
What do you think of obsoleting or deleting implicit typing? Read the discussions I linked and let me know in the comments.