forked from mom-ocean/MOM6
-
Notifications
You must be signed in to change notification settings - Fork 73
Code style guide
Rob Cermak edited this page Feb 26, 2016
·
28 revisions
Code style is typically a personal choice. When styles clash
- No tabs
- No trailing white space
- Indents should be consistent (same amount used in contiguous blocks)
- Preferred indent is 2 spaces
- "preferred" might understate the reaction invoked by other indent amounts! 😉
- No white space between a function name and the opening parenthesis
- White space after all language token
-
if(a==0)is legal fortran but bad style. Useif (a==0)instead. -
if (a == 0)is even better, since==is a language token.
-
- Local variable declarations appear after all the dummy argument declarations. We typically use
! Local variablesto delineate between the argument and local variable declarations. - Local variables should preferably be descriptive multi-character names meaningful in their context, e.g.
del_rho_int(delta rho at interface). - If using a highly abbreviated or short name, the declaration MUST be commented.
- Multi-word names should use snake_case (e.g.
delta_rho).
-
i,j,kare used for cell-center, layer-center references, e.g.h(i,j,k),T(i+1,j,k). -
I,Jare used for staggered, cell-edge references, e.g.u(I,j,k),v(i,J,k),q(I,J,k),u(I-1,j,k). We use a north-east staggering convention so theImeans i+1/2 andI-1means i-1/2. -
Kis used for the interface (between layer) references, e.g.del_t(i,j,K) = T(i,j,K+1) - T(i,j,K). The vertical staggering is such that interfaceK=1is above layerk=1so thatKmeans k-1/2 andK+1means k+1/2.
- Absolutely NO!
- There are a few exceptions which are strictly for debugging non-shared memory applications. Do not use these as an excuse for adding module data.
- All needed data is passed via arguments to subroutines and functions, or as the returned value of a function.
- All arguments must have declared intent, with the exception of pointers: i.e.
intent(in),intent(out),intent(inout). - Opaque types are preferred, i.e. referencing members of types defined in other modules is discouraged.