open-catalog
open-catalog copied to clipboard
Add PWR074: Prefer `use <module>` over `include <source file>`
Just the entry and example codes. The benchmark will be added soon.
Hi @alvrogd, in general this is a nice idea, but sometimes include is exactly what is needed. A use case of include is to implement poor man generics. For example:
function mat_op(a) result(y)
real :: a(..)
real :: y
select rank(a)
rank(0)
include 'long_expression_that_is_rank_agnostic.f90'
rank(1)
include 'long_expression_that_is_rank_agnostic.f90'
rank(2)
include 'long_expression_that_is_rank_agnostic.f90'
end select
end function
A similar, more concrete, example is provided at this implementation of a generic list. In this case, the code depends on a compiler directive. Therefore, it cannot be compiled and used until that is specified.
Just to be clear, there are plenty of cases where this PR makes sense (mostly old F77 code), but distinguishing the cases where include must be kept might be difficult.