intensively (except for file headers).

This document provides an introduction in how the source code of libelektra is organized and how and where to add functionality.

Make sure to read \hyperlink{doc_DESIGN_md}{D\+E\+S\+I\+G\+N} together with this document.

\subsection*{Folder structure}

After you downloaded and unpacked Elektra you see unusually many folders. The reason is that the Elektra project consists of many activities.

The most important are\+:


\begin{DoxyItemize}
\item {\bfseries src\+:} This directory contains the source of the library and the tools.
\item {\bfseries doc\+:} Documentation for the library
\item {\bfseries example\+:} Examples on how to use the library
\item {\bfseries tests\+:} contains the testing framework for the source.
\end{DoxyItemize}

\subsection*{Source Code}

libelektra is the A\+N\+S\+I/\+I\+S\+O C-\/\+Core which coordinates the interactions between the user and the plugins.

The plugins have all kinds of dependencies. It is the responsibility of the plugins to find and check them using C\+Make. The same guidelines apply to all code in the repository including the plugins.

{\ttfamily libloader} is responsible for loading the backend modules. It works on various operating systems by using {\ttfamily libltdl}. This code is optimized for static linking and win32.

kdb is the commandline-\/tool to access and initialize the Elektra database.

\subsubsection*{General Guidelines}

You are only allowed to break a guideline if there is a good reason to do so. When you do, document the fact, either in the commit message, or as comment next to the code.

Of course, all rules of good software engineering apply\+: Use meaningful names and keep the software both testable and reusable.

The purpose of the guidelines is to have a consistent style, not to teach programming.

If you see broken guidelines do not hesitate to fix them. At least put a T\+O\+D\+O marker to make the places visible.

If you see inconsistency do not hesitate to talk about it with the intent to add a new rule here.

See \hyperlink{doc_DESIGN_md}{D\+E\+S\+I\+G\+N} document too, they complement each other.

\subsubsection*{Coding Style}


\begin{DoxyItemize}
\item Limits
\begin{DoxyItemize}
\item Functions should not exceed 100 lines.
\item Files should not exceed 1000 lines.
\item A line should not be longer than 140 characters.
\end{DoxyItemize}
\end{DoxyItemize}

Split up when those limits are reached. Rationale\+: Readability with split windows.


\begin{DoxyItemize}
\item Indentation
\begin{DoxyItemize}
\item Use tabs for indentation.
\item One tab equals 8 spaces.
\end{DoxyItemize}
\item Blocks
\begin{DoxyItemize}
\item Use blocks even for single line statements.
\item Curly braces go on a line on their own on the previous indentation level.
\item Avoid multiple variable declarations at one place.
\item Declare Variables as late as possible, preferable within blocks.
\end{DoxyItemize}
\item Naming
\begin{DoxyItemize}
\item Use camel\+Case for functions and variables.
\item Start types with upper-\/case, everything else with lower-\/case.
\item Prefix names with {\ttfamily elektra} for internal usage. External A\+P\+I either starts with {\ttfamily ks}, {\ttfamily key} or {\ttfamily kdb}.
\end{DoxyItemize}
\item Comments
\begin{DoxyItemize}
\item Use C-\/comments {\ttfamily /$\ast$$\ast$/} with doxygen style for functions.
\item Use C++-\/comments {\ttfamily //} for single line statements about the code in the next line.
\end{DoxyItemize}
\item Whitespaces
\begin{DoxyItemize}
\item Use space before and after equal when assigning a value.
\item Use space before round parenthesis ( {\ttfamily (} ).
\item Use space before and after {\ttfamily $\ast$} from Pointers.
\item Use space after {\ttfamily ,} of every function argument.
\end{DoxyItemize}
\end{DoxyItemize}

\subsubsection*{C Guidelines}


\begin{DoxyItemize}
\item The compiler shall not emit any warning (or error).
\item Use goto only for error situations.
\item Use {\ttfamily const} as much as possible.
\item Use {\ttfamily static} methods if they should not be externally visible.
\item C-\/\+Files have extension {\ttfamily .c}, Header files {\ttfamily .h}.
\end{DoxyItemize}

{\bfseries Example\+:} \href{/home/markus/Projekte/Elektra/current/src/libs/elektra/kdb.c}{\tt src/libs/elektra/kdb.\+c}

\subsubsection*{C++ Guidelines}


\begin{DoxyItemize}
\item Everything as in C if not noted otherwise.
\item Do not use goto at all, use R\+A\+I\+I instead.
\item Do not use raw pointers, use smart pointers instead.
\item C++-\/\+Files have extension {\ttfamily .cpp}, Header files {\ttfamily .hpp}.
\item Do not use {\ttfamily static}, but anonymous namespaces.
\item Write everything within namespaces and do not prefix names.
\item Even though we use C++11, we should be oriented towards https\+://github.com/isocpp/\+Cpp\+Core\+Guidelines/blob/master/\+Cpp\+Core\+Guidelines.\+md \char`\"{}more safe and modern usage\char`\"{}
\end{DoxyItemize}

{\bfseries Example\+:} \href{http://libelektra.org/tree/master/src/bindings/cpp/include/kdb.hpp}{\tt src/bindings/cpp/include/kdb.\+hpp}

\subsubsection*{Doxygen Guidelines}

{\ttfamily doxygen} is used to document the A\+P\+I and to build the html and pdf output. We also support the import of Markdown pages. Doxygen 1.\+8.\+8 or later is required for this feature (Anyways you can find the \href{http://doc.libelektra.org/api/latest/html/}{\tt A\+P\+I Doc} online). Links between Markdown files will be converted with the \hyperlink{doc_markdownlinkconverter_README_md}{Markdown Link Converter}. {\bfseries Markdown pages are used in the pdf, therefore watch which characters you use and provide a proper encoding!}


\begin{DoxyItemize}
\item use {\ttfamily @} to start Doxygen tags
\item Do not duplicate information available in git in Doxygen comments.
\item Use {\ttfamily \textbackslash{}copydetails}, {\ttfamily @copybrief} and {\ttfamily @copydetails} intensively (except for file headers).
\end{DoxyItemize}

\subsubsection*{File Headers}

Files should start with\+:

\begin{DoxyVerb}        /**
         * @file
         *
         * @brief <short statement about the content of the file>
         *
         * @copyright BSD License (see doc/COPYING or http://www.libelektra.org)
         */\end{DoxyVerb}


Note\+:


\begin{DoxyItemize}
\item {\ttfamily @} {\ttfamily file} has {\itshape no} parameters.
\item {\ttfamily @} {\ttfamily brief} should contain a short statement about the content of the file and is needed so that your file gets listed at \href{http://doc.libelektra.org/api/latest/html/files.html}{\tt http\+://doc.\+libelektra.\+org/api/latest/html/files.\+html}
\end{DoxyItemize}

The duplication of the filename, author and date is not needed, because this information is tracked using git and doc/\+A\+U\+T\+H\+O\+R\+S already. 