fortranfortran77

When is implicit type declaration ever good?


I have a colleague who writes Fortran, generally following the F77 standard. I have had to work with some of their source code and I find the use of implicit type declarations (not using implicit none) really confusing and frustrating. Their reason for doing so is to "eliminate all of those type declarations at the beginning of my program(s)." In my opinion, this is a poor trade off for ruining readability and comprehension of the program and its many subroutines. Are there any other, more valid, reasons for not including implicit none in Fortran programs and subroutines?


Solution

  • Just to be entirely clear, relying on implicit typing is frowned upon by many. With good cause. However, there is one case where where some may view implicit typing the lesser of two evils.

    Implicit typing allows one to have an object which is of a type whose name is not accessible in a scope:

      implicit type(badexample) (d)
    
      type badexample
        integer :: neverever=4
      end type badexample
    
      call sub
    
    contains
    
      subroutine reallybad(badexample)
        integer, optional :: badexample
    ! With the declaration above we can't declare a local variable of explicit
    ! type badexample:
    !   type(badexample) dontdothis
        print*, dontdothis%neverever
      end subroutine reallybad
    
    end
    

    Really, this is a poor excuse to use implicit typing. One which can be avoided by other design choices.


    Under Fortran 77, of course, one cannot use implicit none.