Some languages let you return multiple entities from a function, for example
mean, sd = stats(x(:))
In Fortran you can use a subroutine to do this,
call stats(x,mean,sd)
but it is not clear from the calling code what the inputs and outputs are. Should Fortran be extended to allow procedure calls to be annotated by the INTENTs of the procedure? Then you could write
You could only annotate with in:inout: or out: if the corresponding procedure argument had the same declaration. For subroutines with many arguments, I often write a comment saying what the outputs are, but assertions checked by the compiler would be better. Maybe annotating procedure calls could help the compiler better optimize the code, since it would know what variables are not changed by the procedure call.
In the absence of this language feature, perhaps a tool could be developed that looks at a program and for subroutines with more than N (say N = 2) arguments, adds a comment line with annotations, for example
If you routinely specify INTENT attributes for a procedure’s dummy arguments, and the interface for the procedure is visible at the call site (both good programming practices), then you already have what you need for argument checking.
If you routinely specify INTENT attributes for a procedure’s dummy arguments, and the interface for the procedure is visible at the call site (both good programming practices), then you already have what you need for argument checking.
… by the compiler. OP is asking for a way to make the intents more conveniently visible to the programmer at the call site. He wants to be able to tell just by looking at the call site what are the intents of the arguments, so that seeing something like call foo(bar, baz, buzz) one doesn’t have to go look up the interface.
I’ll admit that a good IDE would make this less urgent though. If you can hover your mouse over a procedure to see it’s interface, that’s probably sufficient.
Can you recommend one such IDE for Windows? Does it handle INTERFACEs with MODULE PROCEDUREs, so that hovering over call foo() leads to foo_vec or foo_mat as appropriate?
Although an IDE with this functionality is useful, the subroutine definition will generally use different names for variables than the code calling it, and the arguments may be in a different order if the caller uses named arguments. Many arguments may be missing in the calling code if they are OPTIONAL. So I still think it would be beneficial for the language to permit annotating arguments with INTENTs, since it would be faster to just look at