coding_style
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
coding_style [2017/10/21 11:30] – [Python] damien | coding_style [2022/09/16 18:16] (current) – [C/C++] ddecoeyer | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== General rules ====== | ||
+ | * All code and documentation is written in English. | ||
+ | * Maximum line length should be 100 characters | ||
+ | |||
+ | ====== C/C++ ====== | ||
+ | |||
+ | A Gerrit repository contains formatter configuration profiles compatible with Eclipse and Visual Studio. Refer to the attached README to know how to use them. | ||
+ | |||
+ | An Eclipse configuration file is available in the Quimesis Drive ([[https:// | ||
+ | ===== Indentation ===== | ||
+ | |||
+ | * 4 spaces | ||
+ | * No tabs ! | ||
+ | |||
+ | ===== Names ===== | ||
+ | |||
+ | * Variables or member functions are camel-case, starting with a lower-case letter | ||
+ | * Classes and structs names start with an upper-case letter | ||
+ | * #defines and values of an enum are all-capitals | ||
+ | * namespaces are lower-case | ||
+ | * In C, prefix the function names with a pseudo-namespace/ | ||
+ | |||
+ | ===== File names ===== | ||
+ | |||
+ | * Use .c extension when the unit should be compiled with a C compiler (gcc) | ||
+ | * Use .cpp extension when the unit should be compiled with a C++ compiler (g++) | ||
+ | * In C++, use one .hpp/.cpp per class, with the files having the name of the class | ||
+ | |||
+ | <code cpp MyClass.hpp> | ||
+ | #ifndef MY_CLASS_HPP__ | ||
+ | #define MY_CLASS_HPP__ | ||
+ | |||
+ | class MyClass | ||
+ | { | ||
+ | public: | ||
+ | MyClass(); | ||
+ | ~MyClass(); | ||
+ | | ||
+ | void do(); | ||
+ | }; | ||
+ | |||
+ | #endif | ||
+ | |||
+ | </ | ||
+ | |||
+ | <code cpp MyClass.cpp> | ||
+ | #include " | ||
+ | |||
+ | MyClass:: | ||
+ | { | ||
+ | } | ||
+ | |||
+ | MyClass:: | ||
+ | { | ||
+ | } | ||
+ | |||
+ | void MyClass:: | ||
+ | { | ||
+ | // do something | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | * For all other cases, use lowercase-with-underscore filenames. | ||
+ | |||
+ | ===== C headers ===== | ||
+ | |||
+ | Protect your C headers for C++ inclusions: | ||
+ | |||
+ | <code cpp my_header.h> | ||
+ | |||
+ | #ifndef MY_HEADER_H__ | ||
+ | #define MY_HEADER_H__ | ||
+ | |||
+ | #ifdef __cplusplus | ||
+ | extern " | ||
+ | { | ||
+ | #endif | ||
+ | |||
+ | void unit_myFunction(void); | ||
+ | |||
+ | #ifdef __cplusplus | ||
+ | } | ||
+ | #endif | ||
+ | |||
+ | #endif | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Braces ===== | ||
+ | |||
+ | * Curly braces go on their own line | ||
+ | <code cpp> | ||
+ | if ( a == b ) | ||
+ | { | ||
+ | // do something | ||
+ | } | ||
+ | </ | ||
+ | * Use curly braces even for one-line blocks | ||
+ | * Use parentheses even when precedence of operators applies | ||
+ | |||
+ | ===== Documentation ===== | ||
+ | |||
+ | * Use Doxygen syntax ( http:// | ||
+ | * Prefer self-explanatory names over extended comments. | ||
+ | * README files could be necessary; in which case it is recommended to use [[https:// | ||
+ | ====== Python ====== | ||
+ | |||
+ | * Respect the PEP8 guidelines: | ||
+ | * https:// | ||
+ | * http:// | ||
+ | |||
+ | ====== Abbreviations ====== | ||
+ | |||
+ | Do not overuse abbreviations and acronyms to keep the code clear. | ||
+ | However for common and well known names, use below table. | ||
+ | |||
+ | ^ Abbreviation ^ Meaning ^ | ||
+ | | cbf | Callback Function | | ||
+ | | ptr | Pointer | | ||
+ | |||
+ | ====== Recommended external libraries ====== | ||
+ | |||
+ | Here is a list of well known libraries that provide various kinds of functionalities. Whenever you need one of them, prefer to use the below library so that we keep a uniform code-base. | ||
+ | |||
+ | ===== 0MQ ===== | ||
+ | |||
+ | http:// | ||
+ | |||
+ | ZeroMQ, and its multiple bindings like py-zmq, is a transport layer for inter-process, | ||
+ | |||
+ | ===== python3 ===== | ||
+ | |||
+ | Whenever possible use python3 instead of python2. | ||
+ | |||
+ | When writing Python code, make sure it is python3 compatible. | ||
+ | |||
+ | ===== Google Test ===== | ||
+ | |||
+ | https:// | ||
+ | |||
+ | Google Test is a test framework for C/C++. It is the recommended way to write Unit Tests for C++ code. | ||
+ | |||
+ | ===== Qt5 ===== | ||
+ | |||
+ | http:// | ||
+ | |||
+ | When developing graphical applications, | ||
+ | |||
+ | ===== Herqq UPnP ===== | ||
+ | |||
+ | http:// | ||
+ | |||
+ | A standard-compliant UPnP library to build devices and control points. | ||
+ | |||
+ | ===== Mosquitto (MQTT) ===== | ||
+ | |||
+ | http:// | ||
+ | |||
+ | Ubuntu package to install: '' | ||
+ | |||
+ | |||
+ | ===== JSON ===== | ||
+ | |||
+ | https:// | ||
+ | |||
+ | Ubuntu package to install: '' | ||
+ | |||
+ | ===== Serial port ===== | ||
+ | |||
+ | http:// | ||
+ | |||
+ | Ubuntu package to install: '' | ||
+ | |||
+ | ===== Suggestions ===== | ||
+ | |||
+ | * switch case indentation: | ||
+ | <code cpp> | ||
+ | switch(< | ||
+ | { | ||
+ | case < | ||
+ | { | ||
+ | < | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | </ |
coding_style.txt · Last modified: 2022/09/16 18:16 by ddecoeyer