guidelines.tex 3.73 KB
Newer Older
Bernd Flemisch's avatar
Bernd Flemisch committed
1
\section{Guidelines} 
Philipp Nuske's avatar
Philipp Nuske committed
2
\label{guidelines}
Bernd Flemisch's avatar
Bernd Flemisch committed
3

4
5
6
7
8
9
10
11
12
13
14
15
16
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
is almost a verbatim copy of the DUNE coding guidelines found at
\cite{DUNE-HP}. These guidelines are also recommended for coding with
\Dumux as developer and user.

In order to keep the code maintainable we have decided upon a set of
coding rules.  Some of them may seem like splitting hairs to you, but
they do make it much easier for everybody to work on code that hasn't
been written by oneself.
Bernd Flemisch's avatar
Bernd Flemisch committed
17
18
19
20

\begin{itemize}
\item Naming: 
\begin{itemize}
21
\item Comments: they are helpful! Please document freely what each part of your code does. 
Christoph Grueninger's avatar
Christoph Grueninger committed
22
\item all comments / documentation is in English
Bernd Flemisch's avatar
Bernd Flemisch committed
23
\item Variables: Names for variables should only consist of letters and digits. The first letter should be a lower case one. If your variable names consists of several words, then the first letter of each new word should be capital. As we decided on the only exception are the begin and end methods.
24
25
26
\item Variables should be named as self-explaining as possible: especially abbreviations should be avoided (saturation in stead of S)
\item Method parameters which are not self-explanatory should always
  have a meaningful comment a at calling sites. Example:
Christoph Grueninger's avatar
Christoph Grueninger committed
27
\begin{lstlisting}[style=DumuxCode]
28
29
30
   localResidual.eval(/*includeBoundaries=*/true);
\end{lstlisting}
\item Private Data Variables: Names of private data variables end with an underscore and are the only variables that contain underscores. 
Bernd Flemisch's avatar
Bernd Flemisch committed
31
32
33
34
35
36
\item Typenames: For typenames, 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 The Exlusive-Access Macro: Every header file traditionally begins with the definition of a preprocessor constant that is used to make sure that each header file is only included once. If your header file is called 'myheaderfile.hh', this constant should be DUNE\_MYHEADERFILE\_HH.
\item Files: Filenames should consist of lower case letters exclusively. Header files get the suffix .hh, implementation files the suffix .cc
\end{itemize}
\item Documentation:
Benjamin Faigle's avatar
Benjamin Faigle committed
37
      \Dumux, as any software project of similar complexity, will stand and fall with the quality of its documentation.
38
Therefore it is of paramount importance that you document well everything you do! 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}
Bernd Flemisch's avatar
Bernd Flemisch committed
39
\begin{itemize}
40
\item Method Parameters (in / out)
Bernd Flemisch's avatar
Bernd Flemisch committed
41
\item Template Parameters
42
\item Return Values 
Bernd Flemisch's avatar
Bernd Flemisch committed
43
44
45
46
47
48
49
50
51
52
\item Exceptions thrown by a method
 \end{itemize}
     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 DuneEx.
\item Debugging Code:
      Global debugging code is switched off by setting the symbol NDEBUG. In particular, all asserts are 
53
automatically removed. Use those asserts freely!
Bernd Flemisch's avatar
Bernd Flemisch committed
54
\end{itemize}