-
Notifications
You must be signed in to change notification settings - Fork 19
MAPL Coding standards
Procedure names should generally be verbs and in camel_case. E.g., get_next_token()
.
The importance of a variable name depends on its scope. The names of module variables being the most crucial, and local variables within a procedure being the least crucial. Dummy argument names are intermediate.
Abbreviations should be avoided unless exceptionally clear and consistently applied. The common exception is a prefix to indicate "number of", e.g., n_bins
is an acceptable abbreviation of number_of_bins
. While this convention can lead to longish names, the Fortran ASSOCIATE
construct allows aliases to be used within formulae:
associate (G => universal_gravitational_constant)
f = G * m1 * m2 / r**2
end associate
Multiword variable names should use snake_case.
A variable name should be a noun, and generally be singular. The exception is for containers (arrays, lists, vectors) where plural nouns are more appropriate. For example
real :: density_of_air
integer, allocatable :: items(:)
Note that this rule can be subtle. E.g. we use 3D arrays to represent fields, but usually refer to these fields in the singular:
type(ESMF_Field) :: humidity
The names of derived types should be singular nouns and generally be written in CamelCase. E.g,:
IdentityRegridder
.
Module names should generally have a package-indicator prefix and not have a suffix. E.g., MAPL_HistoryGridComp
. The major exception to this is for the top module for a package which usually just consists of a set of USE statements. These module names should just be the package name. E.g., MAPL
.
Multiword module names should use CamelCase.
In the common case where a module declares a single public derived type, the module name should correspond to the name of that derived type. Note: module names have a package prefix but derived type names do not. E.g., the module. E.g., the module pf_DirectoryService
provides the derived type DirectoryService
.
Ideally each source file will will consist of a single program unit: subroutine, function, module, or program. The name of the file should correspond to the contained program unit. If the contained program unit is a module, the file name should not include the package-indicator prefix.
The file-type suffix should generally be .F90
indicating the use of free format and allowing the use of FPP/CPP macros.
For example, the file containing the module MAPL_HistoryGridComp
should be called HistoryGridComp.F90