Elektra
0.8.20
|
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 DESIGN together with this document.
After you downloaded and unpacked Elektra you should see some folders. The most important are:
libelektra is the ANSI/ISO C99-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 CMake. The same guidelines apply to all code in the repository including the plugins.
libloader
is responsible for loading the backend modules. It works on various operating systems by using libltdl
. This code is optimized for static linking and win32.
kdb is the commandline-tool to access and initialize the Elektra database.
You are only allowed to break a guideline if there is a good reason to do so. When you do, document the fact 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 code that breaks guidelines do not hesitate to fix them. At least put a TODO marker to make the places visible.
If you see inconsistency within the rules do not hesitate to talk about it with the intent to add a new rule here.
See DESIGN document too, they complement each other.
Code is not only for the computer, but it should be readable for humans, too. Up-to-date code comments are essential to make code understandable for others. Thus please use following techniques (in order of preference):
/**/
and Doxygen, see below.You should also add assertions to state what should be true at a specific position in the code. Their syntax is checked and they are automatically verified at run-time. So they are not only useful for people reading the code but also for tools. Assertions in Elektra are used by:
#include <kdbassert.h>
ELEKTRA_ASSERT (condition, "formatted text to be printed when assert fails", ...)
Note: Do not use assert for user-APIs, always handle arguments of user-APIs like untrusted input.
If the "comment" might be useful to be printed during execution, use logging:
#include <kdblogger.h>
ELEKTRA_LOG ("formatted text to be printed according log filters", ...)
Read HERE for how to enable the logger.
//
or with /**/
for multi-line comments.Split up when those limits are reached. Rationale: Readability with split windows.
elektra
for internal usage. External API either starts with ks
, key
or kdb
.(
).*
from Pointers.,
of every function argument.The reformat script can ensure most code style rules, but it is obviously not capable of ensuring everything (e.g. naming conventions). So do not give this responsibility out of hands entirely.
const
as much as possible.static
methods if they should not be externally visible..c
, Header files .h
.Example: src/libs/elektra/kdb.c
.cpp
, Header files .hpp
.static
, but anonymous namespaces.Example: src/bindings/cpp/include/kdb.hpp
.md
or integrated within Doxygen comments#
characters at the left side of headers/titlesREADME.md
and tutorials should be written exclusively with shell recorder syntax so that we know that the code in the tutorial produces output as expecteddoxygen
is used to document the API 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 API Doc online). Links between Markdown files will be converted with the Markdown Link Converter. Markdown pages are used in the pdf, therefore watch which characters you use and provide a proper encoding!
@
to start Doxygen tags\copydetails
, @copybrief
and @copydetails
intensively (except for file headers).Files should start with:
/** * @file * * @brief <short statement about the content of the file> * * @copyright BSD License (see LICENSE.md or https://www.libelektra.org) */
Note:
@
file
has no parameters.@
brief
should contain a short statement about the content of the file and is needed so that your file gets listed at https://doc.libelektra.org/api/latest/html/files.htmlThe duplication of the filename, author and date is not needed, because this information is tracked using git and doc/AUTHORS.md already.