open-catalog icon indicating copy to clipboard operation
open-catalog copied to clipboard

Add PWR074: Prefer `use <module>` over `include <source file>`

Open alvrogd opened this issue 1 year ago • 1 comments

Just the entry and example codes. The benchmark will be added soon.

alvrogd avatar Jul 18 '24 16:07 alvrogd

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.

RRiva avatar Sep 24 '24 14:09 RRiva