We discussed a few basic rules to rename functions and variables in a more explicit and homogeneous (and thus easily and quickly understandable) way. These are fully open for discussions, feedback, suggestions.
RENAMING FUNCTIONS
- All function names should have at least two terms (and could have potentially a third term, a complement)
-
an action verb:
If the return value is a bool: the verb is by default “check”
If the return value is numerical : the verb is by default “calc”
If the return value is void: the verb should be as explicit as possible regarding the actual biological processes (e.g. “disperse_seeds”)
-
an object, vector or a variable:
The object, vector or variable that is affected by the verb (1).
If a current function actually acts on different objects, then this should lead us to split it in different functions (e.g. UpdateField should be splitted in update_LAI3D, update_SWC….)
- Written as snake_case:
the verb is all in lowercase
the object/var/object is also in lowercase, when not corresponding to an actual declared object/vector/variables, otherwise it uses the name of the declared object/var/object (which is written as CamelCase, see suggested guidelines for variables)
E.g. of changes:
Birth -> initiate_Tree
Death -> kill_Tree
Water-uptake -> uptake_Water
DisperseSeeds -> disperse_seeds
All functions starting by "Get" or "Make" should start by "calc"
RENAMING VARIABLES (less clear)
Renaming variables:
- Written as CamelCase (nbTreefall10 -> NbTreefall10 )
- When a variable is one of an object of a specific class, it used to start by the class first letter (e.g. “t_LMA” and “s_LMA”; this was useful and needed for the first versions of the code in which some class variables were used in functions that were not methods… but we believe it is no longer still useful, especially after the refactoring effort)
- Uppercase for the constant and Macros: PI, ABSZERO, AIRMA, WATER
- Prefix LookUp_ for the lookup tables: LookUpKmT, LookUpGammaT, LookUpVcmaxT, LookUpRleaf, LookUpFluxAbsorption….
- Statistics prefix for statistic parameters Sigma / Corr / Cov: SigmaHeight, CorrNmassPmass, CovNmassPmass
- Time aggregate suffix All /Year: WindDailyMeanAll, TemperatureDailyMeanYear
- _Option for options:
|
struct ModelOptions |
|
{ |
|
bool _NONRANDOM; |
|
bool _GPPcrown; |
|
bool _BASICTREEFALL; |
|
bool _SEEDTRADEOFF; |
|
bool _NDD; |
|
bool _CROWN_MM; |
|
bool _sapwood; |
|
bool _seedsadditional; |
|
bool _LL_parameterization; |
|
bool _FromInventory; |
|
bool _OUTPUT_extended; |
|
bool _OUTPUT_inventory; |
|
int _LA_regulation; |
|
int _OUTPUT_pointcloud; |
|
int _SOIL_LAYER_WEIGHT; |
|
int _WATER_RETENTION_CURVE; |
We discussed a few basic rules to rename functions and variables in a more explicit and homogeneous (and thus easily and quickly understandable) way. These are fully open for discussions, feedback, suggestions.
RENAMING FUNCTIONS
an action verb:
If the return value is a bool: the verb is by default “check”
If the return value is numerical : the verb is by default “calc”
If the return value is void: the verb should be as explicit as possible regarding the actual biological processes (e.g. “disperse_seeds”)
an object, vector or a variable:
The object, vector or variable that is affected by the verb (1).
If a current function actually acts on different objects, then this should lead us to split it in different functions (e.g. UpdateField should be splitted in update_LAI3D, update_SWC….)
the verb is all in lowercase
the object/var/object is also in lowercase, when not corresponding to an actual declared object/vector/variables, otherwise it uses the name of the declared object/var/object (which is written as CamelCase, see suggested guidelines for variables)
E.g. of changes:
Birth -> initiate_Tree
Death -> kill_Tree
Water-uptake -> uptake_Water
DisperseSeeds -> disperse_seeds
All functions starting by "Get" or "Make" should start by "calc"
RENAMING VARIABLES (less clear)
Renaming variables:
TROLL/include/context.hpp
Lines 63 to 80 in 6959887