2012-10-17 08:48:43 -05:00
|
|
|
\chapter{Coding Style Guidelines}
|
2010-09-23 08:29:30 -05:00
|
|
|
\label{guidelines}
|
2008-09-25 14:52:48 -05:00
|
|
|
|
2011-08-29 07:07:11 -05:00
|
|
|
An important characteristic of source code is that it is written only
|
|
|
|
once but usually it is read many times (e.g. when debugging things,
|
|
|
|
adding features, etc.). For this reason, good programming frameworks
|
|
|
|
always aim to be as readable as possible, even if comes with higher
|
|
|
|
effort to write them in the first place. The remainder of this section
|
2012-10-17 08:48:43 -05:00
|
|
|
is very similar to the \Dune coding guidelines found at the \Dune
|
|
|
|
website~\cite{DUNE-HP}. These guidelines are also strongly recommended
|
|
|
|
for working with \eWoms. Some of these coding style rules may seem
|
|
|
|
like splitting hairs to you, but they do make it much easier for
|
|
|
|
everybody to work on code that has not been written by oneself.
|
2008-09-25 14:52:48 -05:00
|
|
|
|
|
|
|
\begin{itemize}
|
|
|
|
\item Naming:
|
|
|
|
\begin{itemize}
|
2012-10-17 08:48:43 -05:00
|
|
|
\item Comments: They are helpful! Use comments extensively to explain
|
|
|
|
what your code does, but please refrain from adding trivial
|
|
|
|
comments. Trivial comments are, for example comments that only
|
|
|
|
parrot the source code (``this method sets a'' as the comment for a
|
|
|
|
method called \texttt{setA()}), or comments that explain language
|
|
|
|
features (``if b is true then a is c else d'' for the statement
|
|
|
|
\texttt{a = b?c:d}).
|
|
|
|
\item All comments, documentation and variable or type names are
|
|
|
|
exclusivly using the English language.
|
|
|
|
\item Variables: Names for variables should only feature letters and
|
|
|
|
digits. The first letter should be lower case. If your variable
|
|
|
|
names consists of several words, then the first letter of each new
|
|
|
|
word should be capitalized.
|
|
|
|
\item Variables and methods should be named as self-explanatory as
|
|
|
|
possible. Especially, this means abbreviations should be avoided
|
|
|
|
(for example, use 'saturation' in stead of 'S')
|
2011-08-29 07:07:11 -05:00
|
|
|
\item Method parameters which are not self-explanatory should always
|
|
|
|
have a meaningful comment a at calling sites. Example:
|
2012-10-15 09:57:17 -05:00
|
|
|
\begin{lstlisting}[style=eWomsCode]
|
2011-08-29 07:07:11 -05:00
|
|
|
localResidual.eval(/*includeBoundaries=*/true);
|
|
|
|
\end{lstlisting}
|
2012-10-17 08:48:43 -05:00
|
|
|
\item Private attributes: Names of private attributes should end with
|
|
|
|
an underscore and are supposed to be the only variables that contain
|
|
|
|
underscores.
|
|
|
|
\item Typenames: For typenames (classes, structures, typedefs, etc),
|
|
|
|
the same rules as for variables apply. The only difference is that
|
|
|
|
the first letter should be a capital one.
|
|
|
|
\item Macros: The use of preprocessor macros is strongly
|
|
|
|
discouraged. If you have to use them for whatever reason, please use
|
|
|
|
capital letters only.
|
|
|
|
\item Guardian macros: Every header file traditionally begins with the
|
|
|
|
definition of a preprocessor macro that is used to make sure that
|
|
|
|
the header file is only included once. If your header file is
|
|
|
|
called 'myheaderfile.hh', this constant should be named
|
2012-11-18 09:42:57 -06:00
|
|
|
\texttt{EWOMS\_MYHEADERFILE\_HH}.
|
2012-10-17 08:48:43 -05:00
|
|
|
\item Files: File names should exclusively consist of lower case
|
|
|
|
letters. Header files get the suffix .hh, implementation files the
|
|
|
|
suffix .cc
|
2008-09-25 14:52:48 -05:00
|
|
|
\end{itemize}
|
2012-10-17 08:48:43 -05:00
|
|
|
|
|
|
|
\item Documentation: \eWoms, as any software project of similar
|
|
|
|
complexity, will stand and fall with the quality of its
|
|
|
|
documentation. Therefore, it is of paramount importance that you
|
|
|
|
document everything you do well! We use the doxygen system to
|
|
|
|
extract easily-readable documentation from the source code. Please
|
|
|
|
use its syntax everywhere. In particular, please comment
|
|
|
|
\textbf{all}
|
2008-09-25 14:52:48 -05:00
|
|
|
\begin{itemize}
|
2012-10-17 08:48:43 -05:00
|
|
|
\item Method parameters
|
|
|
|
\item Template parameters
|
|
|
|
\item Return values
|
2008-09-25 14:52:48 -05:00
|
|
|
\item Exceptions thrown by a method
|
|
|
|
\end{itemize}
|
2012-10-17 08:48:43 -05:00
|
|
|
Since we all know that writing documentation is not well-liked and is
|
|
|
|
frequently defered to some vague 'next week', we herewith proclaim
|
|
|
|
the Doc-Me Dogma . It goes like this: Whatever you do, and in
|
|
|
|
whatever hurry you happen to be, please document everything at least
|
|
|
|
with a {\verb /** $\backslash$todo Please doc me! */}. That way at
|
|
|
|
least the absence of documentation is documented, and it is easier to
|
|
|
|
get rid of it systematically.
|
|
|
|
\item Exceptions: The use of exceptions for error handling is
|
|
|
|
encouraged. Until further notice, all exceptions thrown are derived
|
|
|
|
from \texttt{Dune::Exception}.
|
|
|
|
\item Debugging code: Code which is only there to ease the debugging
|
|
|
|
process should always be switched off if the preprocessor macro
|
|
|
|
NDEBUG is defined. In particular, all assertations are automatically
|
|
|
|
removed. Use those assertations freely!
|
2008-09-25 14:52:48 -05:00
|
|
|
\end{itemize}
|
2012-10-17 08:48:43 -05:00
|
|
|
|
|
|
|
%%% Local Variables:
|
|
|
|
%%% mode: latex
|
|
|
|
%%% TeX-master: "ewoms-handbook"
|
|
|
|
%%% End:
|