-
Notifications
You must be signed in to change notification settings - Fork 11
Code conventions
In order for the code to be readable and maintainable, we request that the code adhere to the following standards:
- Indents should be made with 2 tab spaces. For emacs, set:
;; make indentation commands use space only (never tab character)
(setq indent-tabs-mode nil)
;; set default tab char's display width to 2 spaces
(setq tab-width 2)
To make default, change setq
to setq-default
.
-
Variables names : first word starts with a small letter, subsequest words start with capital letters :
variableName
, do not usevariable_name
orVariableName
-
Function names : same as variable names :
functionName
, do not usefunction_name
orFunctionName
-
Macro names : capitalize every letter and seperate words with an underscore :
MACRO_NAME
, do not useMACRONAME
-
Braces should follow the convention:
for ()
{
if ()
{
}
else
{
}
}
-
Comments should always be made with
/* */
-
Do not exceed 80 columns in width.
-
Long formulas are written as follows:
elem->gamma =
sqrt(1 + geom->gCov[1][1]*elem->primVars[U1]*elem->primVars[U1]
+ geom->gCov[2][2]*elem->primVars[U2]*elem->primVars[U2]
+ geom->gCov[3][3]*elem->primVars[U3]*elem->primVars[U3]
+ 2*( geom->gCov[1][2]*elem->primVars[U1]*elem->primVars[U2]
+ geom->gCov[1][3]*elem->primVars[U1]*elem->primVars[U3]
+ geom->gCov[2][3]*elem->primVars[U2]*elem->primVars[U3]
)
);
In particular, notice that
- All the brackets at a particular depth of the equation are aligned vertically.
- Mathematical signs are put at the beginning of the intermediate code.
-
All the functions should have a comment above them describing the input, output and what they do, along with the author.
-
Functions that implement nontrivial formulas should reference which publications they are picked out from. For example, the function
gCovFunc()
has the following description above the function definition
/* The covariant metric in X^mu = {t, X1, X2, phi} coordinates. Inside the
* function, the metric is first defined in the x^mu Kerr-Schild coordinates and
* then transformed into the X^mu coordinates using:
*
* ds^2 = g_mu_nu dx^mu dx^nu
* = (g_mu_nu (dx^mu/dX^alpha) (dx^nu/dX^beta)) dX^alpha dX^beta
* = g_alpha_beta dX^alpha dX^beta
*
* Ref: "A Measurement of the Electromagnetic Luminosity of a Kerr Black Hole"
* Jonathan C. McKinney and Charles F. Gammie
*
* This function is not directly called by the user. All geometrical quantities
* are set by calling setGeometry().
*
* @param Input: X, X^mu coordinates REAL X[NDIM] array
* @param Output: gCov, The covariant metric, REAL gCov[NDIM][NDIM] array
*/