Skip to content
Snippets Groups Projects
4_guidelines.tex 3.67 KiB
Newer Older
Thomas Fetzer's avatar
Thomas Fetzer committed
\section{Coding Guidelines}
Thomas Fetzer's avatar
Thomas Fetzer committed
\label{sc_guidelines}
Writing code in a readable manner is very important, especially
for future code developers (e.g. for adding features, debugging, etc.).
This section is inspired by the DUNE coding guidelines
\url{http://www.dune-project.org/doc/devel/codingstyle.html}, which is strongly
recommended.
Thomas Fetzer's avatar
Thomas Fetzer committed

\paragraph{Documentation:}
Please document freely what each part of your code does. All comments/ documentation
Thomas Fetzer's avatar
Thomas Fetzer committed
is in \textbf{English}.
We proclaim the Doc-Me Dogma, which means whatever you do, please document
it least with
\begin{lstlisting}[style=DumuxCode]
  /*! \todo Please doc me! */
\end{lstlisting}
That way at least the absence of documentation is documented, and it is easier
to get rid of it systematically. Please comment \textbf{all}:
\begin{itemize}
Thomas Fetzer's avatar
Thomas Fetzer committed
  \item Method Parameters (in / out)
  \item Method parameters which are not self-explanatory should always
        have a meaningful comment at calling sites. Example:
  \begin{lstlisting}[style=DumuxCode]
    localResidual.eval(/*includeBoundaries=*/true);
  \end{lstlisting}
  \item Template Parameters
Thomas Fetzer's avatar
Thomas Fetzer committed
  \item Return Values
Thomas Fetzer's avatar
Thomas Fetzer committed
  \item Exceptions thrown by a method
\end{itemize}
Thomas Fetzer's avatar
Thomas Fetzer committed

\paragraph{Naming:}
Thomas Fetzer's avatar
Thomas Fetzer committed
To avoid duplicated types or variables and for a better understanding and usability
of the code we have the following naming conventions:
\begin{itemize}
Thomas Fetzer's avatar
Thomas Fetzer committed
\item \textbf{Variables/Functions \ldots}
Thomas Fetzer's avatar
Thomas Fetzer committed
  \begin{itemize}
Thomas Fetzer's avatar
Thomas Fetzer committed
  \item start in \emph{lower} case and contain letters.
  \item \emph{CamelCase}: if the name consists of  several words, then
        the first letter of a new word is capital.
  \item \emph{Self-Explaining}: in general abbreviations should be avoided (write saturation in stead of S)
Thomas Fetzer's avatar
Thomas Fetzer committed
  \item \emph{Abbreviations}: If and only if a single letter that represents an
         abbreviation or index is followed by a single letter (abbreviation or index),
         CamelCase is \textbf{not} used. An inner-word underscore is only permitted if
Thomas Fetzer's avatar
Thomas Fetzer committed
         it symbolizes a fraction line. Afterwards, we continue with lower case, i.e.
Thomas Fetzer's avatar
Thomas Fetzer committed
         the common rules apply to both enumerator and denominator. Examples:
  \begin{itemize}
      \item \texttt{pw} but \texttt{pressureW} $\rightarrow$ because ``pressure'' is a word.
      \item \texttt{srnw} but \texttt{sReg} $\rightarrow$ because ``reg'' is not an
            abbreviation of a single letter. ``n'' abbreviates ``non'',
             ``w'' is ``wetting'', so not CamelCase.
      \item \texttt{pcgw} but \texttt{dTauDPi} $\rightarrow$ Both ``Tau'' and ``Pi''
            are words, plus longer than a letter.
      \item \textbf{But:} \texttt{CaCO3} The only exception: chemical formulas are
            written in their chemically correct way $\rightarrow$ \texttt{CaCO3}
  \end{itemize}
Thomas Fetzer's avatar
Thomas Fetzer committed
  \end{itemize}
Thomas Fetzer's avatar
Thomas Fetzer committed
\item \textbf{Private Data Variables:} Names of private data variables end with an
Thomas Fetzer's avatar
Thomas Fetzer committed
      underscore and are the only variables that contain underscores.
Thomas Fetzer's avatar
Thomas Fetzer committed
\item \textbf{Type names:} For type names, the same rules as for variables apply. The
Thomas Fetzer's avatar
Thomas Fetzer committed
      only difference is that the \emph{first letter is capital}.
\item \textbf{Files:} File names should consist of \emph{lower case} letters
      exclusively. Header files get the suffix \texttt{.hh}, implementation files the
      suffix \texttt{.cc}
\item \textbf{The Exclusive-Access Macro:} Every header file traditionally begins
      with the definition of a preprocessor constant that is used to make sure that
Thomas Fetzer's avatar
Thomas Fetzer committed
      each  header file is only included once. If your header file is called
Thomas Fetzer's avatar
Thomas Fetzer committed
      'myheaderfile.hh', this constant should be DUMUX\_MYHEADERFILE\_HH.
Thomas Fetzer's avatar
Thomas Fetzer committed
\item \textbf{Macros:} The use of preprocessor macros is strongly discouraged. If you
Thomas Fetzer's avatar
Thomas Fetzer committed
      have to use them for whatever reason, please use capital letters only.
\end{itemize}