039. Name modules and the source files containing them consistently, with one module per file#
topic: Modules
The convention @Beliavsky uses is that a module named m_mod is defined in a source file m.f90.
That way if you see
use m_mod, only: foo
in the code you know to look in m.f90 for the definition of foo1.
This also helps to avoid name clashes, since otherwise
“it is quite frequent to have a procedure with the same name,
or a type with the same name as the module”23.
This type of convention is not uncommon. For example:
Curcic’s Modern Fortran (code examples), where the modules are named
mod_<name>and the filesmod_<name>.f90The Community Land Model, where some module names and their source file names are suffixed with
Mod, orTypeif the main purpose of the module is to define a single type@everythingfunctional recommends suffixing module names with
_m(and types with_t) and naming the source file with suffix_m.f90
Additional recommendations:
Prefix module names with the library name to avoid name clashes when used as dependency in other projects
— https://fortran-lang.org/learn/best_practices/modules_programs
Note
Similar to the <name>_mod module naming convention, since Fortran code is case-insensitive,
a convention for naming types is to use <name>_type.
Name modules and the source files containing them consistently, with one module per file. The convention I use is that a module named m_mod is defined in a source file m.f90. That way if I see
— FortranTip (@fortrantip) December 21, 2021
use m_mod, only: foo
in my code I know to look in m.f90 for the definition of foo.
- 1
Note that modern development environments, like this VS Code extension will generally provide go-to-definition functionality.
- 2
- 3