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 files mod_<name>.f90

  • The Community Land Model, where some module names and their source file names are suffixed with Mod, or Type if 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:

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.



1

Note that modern development environments, like this VS Code extension will generally provide go-to-definition functionality.

2

https://everythingfunctional.gitlab.io/fortran-style-guide/

3

Fortran-FOSS-Programmers/Best_Practices