.. _style_guide: ======================= Style Guide for OpenMOC ======================= In order to keep the OpenMOC code base consistent in style, this guide specifies a number of rules which should be adhered to when modified existing code or adding new code in OpenMC. This guide should mostly agree with the `Google style guides`_ for Python and C++. ------------- General Rules ------------- * **Compilation** - Make sure code can be compiled with most common compilers, especially gcc and the Intel C++ compiler icpc. * **Dependencies** - Avoid using special extensions or libraries which add dependencies to the OpenMOC source. * **Code Comments** - Always include comments to describe what your code is doing. Do not be afraid of using copious amounts of comments. ------------------ Source Code Syntax ------------------ The following describes some of the rules for source code syntax, including the class naming convention, rules for class methods and attributes as well as normal routines and variables. Class Names ----------- Class names are CamelCase_ starting with a **capital** letter and without **"_"** between words as illustrated in the C++ snippet below: .. code-block:: c /* Yes */ class MyClass { ... }; /* No */ class myClass { ... }; /* No */ class My_Class{ ... }; Class Methods ------------- Class methods are camelCase_ starting with a **lowercase** letter and without **"_"** between words as illustrated in the Python snippet below: .. code-block:: python class MyClass: # Yes def getterMethod(self): ... # No def Setter_Method(self): ... # No def logic_method(self): ... Class Attributes ---------------- Class attributes are **private** and **lowercase** which start with **"_"** and with "_" between words as illustrated in the C++ snippet below: .. code-block:: c class MyClass { private: /* Yes */ int _first_attribute; /* No */ double second_attribute; /* No */ float _ThirdAttribute; ... }; Function Names -------------- Functions (not class methods) are all **lowercase** with **"_"** between words as illustrated in the Python snippet below: .. code-block:: python # Yes def my_function(a, b): ... # No def myFunction(a, b): ... # No def My_Function(a, b): ... Variable Names -------------- Temporary variables (e.g. variables defined within the scope of a function) are **lowercase** with **"_"** between words as illustrated in the C/C++ snippet below: .. code-block:: c void my_function(int a, int b) { /* Yes */ int first_variable; /* No */ int secondVariable; /* No */ int Second_Variable; ... } .. _code_comments: ------------- Code Comments ------------- OpenMOC uses Doxygen_ for automated generation of Application Programming Interface (API_) documentation based upon code comments. Please adhere to the Doxygen standard for code comments in both C/C++ and Python source code. In particular, * **C/C++ functions** should be preceded by Doxygen-style comments as illustrated in the following code snippet: .. code-block:: c /** * @brief Single precision A*X plus Y * @details Multiplies single precision vectors a and x and * adds vector y. The output vector is stored in y. * @param n the size of the vectors x and y * @param a a single precision vector of length n * @param x a single precision vector of length n * @param y a single precision vector of length n */ int saxpy(int n, float* a, float* x, float* y) { for (int i=0; i