The recent discussion about INTERFACE in Fortran begs the
question whether we need the INTERFACE construct at all.
I think not and I will argue my point.
INTERFACE is used for three different cases:
a) generic procedures or "overloading"
Other languages do not provide an extra construct for this
they just distinguish procedures by "type", i.e. argument lists
(and return results) have to have at least one different element
to allow a distinction
From this point of view there is no need though it may be nice
to put overloading "in writing".
b) defining operators
Again, languages like Ada do it simply by naming the operator
in the procedure name. E.g. in pseudo-fortran:
function, operator, public :: ".add."( a, b) result (c)
real, intent(in) :: a,b
real :: c
c = a+1.0/b
end function ".add."
Fortran currently requires quite a number of statements to achieve
the same as the above pseudo-code which is really annoying:
1) a function
2) an INTERFACE operator statement
3a) since the function name should be kept hidden, a private statement
for the function name
3b) or, if the module has a global private statement, a public
statement for the operator
The F subset requires explicit private/public statements, i.e. 3a and 3b.
3 (or, in F, 4) Fortran constructs are needed to express one simple idea,
in different places in a module. Yuck.
c) defining INTERFACEs for external procedures
This is partly intended as providing a bridge between Fortran 77
and new Fortran 90 codes.
BUT does it make codes safer and easier to maintain?
If one has access to the original F77 code it can easily be wrapped
into a module and use'd which would make any INTERFACE superfluous.
(About the same effort as writing/copying the INTERFACEs.)
If access to the F77 code is only via an object library the
INTERFACE can help but only in a very limited way. It makes sure that
procedures are called within the relevant scoping unit in a
consistent way but it does not ensure that the INTERFACE of the
actual procedure is checked against the INTERFACE construct which
is at the heart of the matter. If the INTERFACE can be checked it
could be done at the level of invoking the procedure as well, i.e.
the INTERFACE is superfluous.
INTERFACEs increase the effort to maintain codes since any change
to any procedure argument list must be done in the INTERFACEs
and the actual calls as well.
Item c) is really a quality of implementation issue for compilers
and is not solved by adding INTERFACEs but by wrapping everything
into modules, one of the good side-effects of modules.
Hence my verdict on INTERFACEs is: essentially useless since everything
could easily be achieved by other means and often more succinctly,
elegantly and safely.
Cheers,
WWS
-----------------------------------------------------------------------
| Werner W Schulz |
| Dept of Chemistry email: [log in to unmask] |
| University of Cambridge Phone: (+44) (0)1223 336 502 |
| Lensfield Road Secretary: 1223 336 338 |
| Cambridge CB2 1EW Fax: 1223 336 536 |
| United Kingdom WWW: |
-----------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|