2014-10-07 12:19:46 +04:00
|
|
|
C++ Coding Style
|
|
|
|
================
|
|
|
|
|
2018-04-03 02:45:08 +03:00
|
|
|
Kakoune is written in C++14, here are the main coding style points:
|
2014-10-07 12:19:46 +04:00
|
|
|
|
2019-11-16 13:27:06 +03:00
|
|
|
* Avoid external dependencies besides posix/stdc++
|
2014-10-07 12:19:46 +04:00
|
|
|
|
|
|
|
* 4 spaces for indentation, no tabs
|
|
|
|
|
|
|
|
* public interface before private methods/data when defining a class
|
|
|
|
|
2016-04-08 19:00:24 +03:00
|
|
|
* use +override+ keyword for overridden virtual methods
|
2014-10-07 12:19:46 +04:00
|
|
|
|
|
|
|
* opening brackets on their own lines by default, except when declaring
|
|
|
|
an object where the opening bracket follows the equal sign.
|
|
|
|
|
2018-04-03 02:45:08 +03:00
|
|
|
* use alternative logical operator names (and, or, not instead of &&, ||, !)
|
|
|
|
|
2014-10-07 12:19:46 +04:00
|
|
|
-----
|
|
|
|
int func()
|
|
|
|
{
|
|
|
|
if (condition)
|
|
|
|
{
|
|
|
|
...
|
|
|
|
}
|
|
|
|
else
|
|
|
|
statement;
|
|
|
|
}
|
|
|
|
|
|
|
|
int array[] = {
|
|
|
|
...
|
|
|
|
};
|
|
|
|
-----
|
|
|
|
|
|
|
|
* End lines with an operator when continuing on the next line
|
|
|
|
|
|
|
|
----
|
2018-04-03 02:45:08 +03:00
|
|
|
if (condition1 or
|
2014-10-07 12:19:46 +04:00
|
|
|
condition2)
|
|
|
|
----
|
|
|
|
|
|
|
|
* Try to keep under 80 columns, even though this is not a strict limit.
|
|
|
|
|
|
|
|
* CamelCase for types, snake_case for variables/function names
|
|
|
|
|
|
|
|
* prefix fields with m_, static ones with ms_ except for dumb structs
|
|
|
|
(struct with every field public) where these prefixes can be dropped.
|
|
|
|
|
|
|
|
* use const and constexpr liberally
|