<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://kodi.wiki/index.php?action=history&amp;feed=atom&amp;title=Contributing_code</id>
	<title>Contributing code - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://kodi.wiki/index.php?action=history&amp;feed=atom&amp;title=Contributing_code"/>
	<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Contributing_code&amp;action=history"/>
	<updated>2026-05-27T15:49:59Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://kodi.wiki/index.php?title=Contributing_code&amp;diff=235022&amp;oldid=prev</id>
		<title>RogueScholar: Add toclimit-2 class to TOC div tag</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Contributing_code&amp;diff=235022&amp;oldid=prev"/>
		<updated>2021-09-29T14:28:30Z</updated>

		<summary type="html">&lt;p&gt;Add toclimit-2 class to TOC div tag&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 14:28, 29 September 2021&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l2&quot;&gt;Line 2:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 2:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Motivation ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Motivation ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;div style=&quot;float: right; margin-left: &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;1.5em&lt;/del&gt;;&quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;div &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;class=&quot;toclimit-2&quot; &lt;/ins&gt;style=&quot;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;clear: both; margin-bottom: 0.5em; &lt;/ins&gt;float: right; margin-left: &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;2em; width: auto&lt;/ins&gt;;&quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;When working in a large group, the two most important values are readability and maintainability. We code for other people, not computers. To accomplish these goals, we have created a unified set of code conventions. Conventions can be bent or broken in the interest of making code more readable and maintainable. However, if you submit a patch that contains excessive style conflicts, you may be asked to improve your code before your [[Merge window|pull request]] is fully reviewed.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;When working in a large group, the two most important values are readability and maintainability. We code for other people, not computers. To accomplish these goals, we have created a unified set of code conventions. Conventions can be bent or broken in the interest of making code more readable and maintainable. However, if you submit a patch that contains excessive style conflicts, you may be asked to improve your code before your [[Merge window|pull request]] is fully reviewed.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>RogueScholar</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Contributing_code&amp;diff=235021&amp;oldid=prev</id>
		<title>RogueScholar: Add current coding conventions to eponymous article on wiki</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Contributing_code&amp;diff=235021&amp;oldid=prev"/>
		<updated>2021-09-29T13:33:52Z</updated>

		<summary type="html">&lt;p&gt;Add current coding conventions to eponymous article on wiki&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;As a large and mature open source software project, Team Kodi has to integrate the work of hundreds of developers into a single, cohesive codebase. This is accomplished by insisting that those who wish to contribute do so according to a clear and explicit set of conventions, procedures and rubrics. This article is meant to organize them on a single page but is far from exhaustive; deeper study is almost certain to be required.&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
&amp;lt;div style=&amp;quot;float: right; margin-left: 1.5em;&amp;quot;&amp;gt;__TOC__&amp;lt;/div&amp;gt;&lt;br /&gt;
When working in a large group, the two most important values are readability and maintainability. We code for other people, not computers. To accomplish these goals, we have created a unified set of code conventions. Conventions can be bent or broken in the interest of making code more readable and maintainable. However, if you submit a patch that contains excessive style conflicts, you may be asked to improve your code before your [[Merge window|pull request]] is fully reviewed.&lt;br /&gt;
&lt;br /&gt;
In the repository root directory, there is a &amp;lt;code&amp;gt;.clang-format&amp;lt;/code&amp;gt; file that implements the rules as specified here. You are encouraged to run &amp;lt;code&amp;gt;clang-format&amp;lt;/code&amp;gt; on any newly created files. It is currently not recommended to do so on preexisting files because all the formatting changes will clutter your commits and pull request.&lt;br /&gt;
&lt;br /&gt;
== Language standard ==&lt;br /&gt;
We currently target the C++14 language standard, so do use C++14 features when possible, but do not use C++17 features.&lt;br /&gt;
&lt;br /&gt;
== Formatting ==&lt;br /&gt;
=== Line length ===&lt;br /&gt;
The &amp;lt;code&amp;gt;ColumnLimit&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;.clang-format&amp;lt;/code&amp;gt; is set to 100, which defines line length (i.e. where lines should be broken) that allows two documents to be displayed side-by-side on a 1080p screen for diffs at a standard DPI.&lt;br /&gt;
&lt;br /&gt;
=== Braces ===&lt;br /&gt;
Curly braces always go on a new line.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
for (int i = 0; i &amp;lt; t; i++)&lt;br /&gt;
{&lt;br /&gt;
  [...]&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if (true)&lt;br /&gt;
{&lt;br /&gt;
  [...]&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Dummy&lt;br /&gt;
{&lt;br /&gt;
  [...]&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Indentation ===&lt;br /&gt;
We use spaces as opposed to tabs to indent, with each level of indentation being two spaces further from the left margin than its parent. Opening curly braces increase the level of indentation for the code enclosed by them, and likewise closing curly braces decrease the level of indentation.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Exception:&amp;#039;&amp;#039;&amp;#039; Do not indent namespaces to simplify nesting them and wrapping &amp;#039;&amp;#039;.cpp&amp;#039;&amp;#039; files in a namespace.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
namespace KODI&lt;br /&gt;
{&lt;br /&gt;
namespace UTILS&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
class ILogger&lt;br /&gt;
{&lt;br /&gt;
public:&lt;br /&gt;
  virtual void Log(...) = 0;&lt;br /&gt;
  virtual ~ILogger() {}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Control statements ===&lt;br /&gt;
Insert a new line before every:&lt;br /&gt;
* &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; in an &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement&lt;br /&gt;
* &amp;lt;code&amp;gt;catch&amp;lt;/code&amp;gt; in a &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; statement&lt;br /&gt;
* &amp;lt;code&amp;gt;while&amp;lt;/code&amp;gt; in a &amp;lt;code&amp;gt;do&amp;lt;/code&amp;gt; statement&lt;br /&gt;
&lt;br /&gt;
==== If/else ====&lt;br /&gt;
Put the consequent on a new line, if not in curly braces anyway. Keep &amp;lt;code&amp;gt;else if&amp;lt;/code&amp;gt; (elif) statements on one line.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
if (true)&lt;br /&gt;
  return;&lt;br /&gt;
&lt;br /&gt;
if (true)&lt;br /&gt;
{&lt;br /&gt;
  [...]&lt;br /&gt;
}&lt;br /&gt;
else if (false)&lt;br /&gt;
{&lt;br /&gt;
  return;&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
  return;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Switch cases ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
switch (cmd)&lt;br /&gt;
{&lt;br /&gt;
  case x:&lt;br /&gt;
  {&lt;br /&gt;
    doSomething();&lt;br /&gt;
    break;&lt;br /&gt;
  }&lt;br /&gt;
  case x:&lt;br /&gt;
  case z:&lt;br /&gt;
    return true;&lt;br /&gt;
  default:&lt;br /&gt;
    doSomething();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Try/catch ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
try&lt;br /&gt;
{&lt;br /&gt;
  [...]&lt;br /&gt;
}&lt;br /&gt;
catch (std::exception&amp;amp; e)&lt;br /&gt;
{&lt;br /&gt;
  [...]&lt;br /&gt;
  throw;&lt;br /&gt;
}&lt;br /&gt;
catch (...)&lt;br /&gt;
{&lt;br /&gt;
  [...]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Whitespace ===&lt;br /&gt;
Conventional operators have to be surrounded by one space on each side.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
a = (b + c) * d;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Control statement keywords have to be separated from opening parentheses by one space.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
while (true);&lt;br /&gt;
for (int i = 0; i &amp;lt; x; i++);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Commas have to be followed by one space.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
void Dummy::Method(int a, int b, int c);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Initializer lists have one space after each element (including the comma), but no surrounding spaces.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
constexpr int aNiceArray[] = {1, 2, 3};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Vertical alignment ===&lt;br /&gt;
Do not use whitespace to vertically align around operators or values. This causes problems on code review if one needs to realign all values to their new position, producing unnecessarily large diffs.&lt;br /&gt;
&lt;br /&gt;
✅ Good:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
int value1{1};&lt;br /&gt;
int value2{2};&lt;br /&gt;
CExampleClass* exampleClass{};&lt;br /&gt;
CBiggerExampleClass* biggerExampleClass{};&lt;br /&gt;
exampleClass = new CExampleClass(value1, value2);&lt;br /&gt;
biggerExampleClass = new CBiggerExampleClass(value1, value2);&lt;br /&gt;
exampleClass-&amp;gt;InitExample();&lt;br /&gt;
biggerExampleClass-&amp;gt;InitExample();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
❌ Bad:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
int                  value1             {1};&lt;br /&gt;
int                  value2             {2};&lt;br /&gt;
[...]&lt;br /&gt;
CExampleClass       *exampleClass       {};&lt;br /&gt;
CBiggerExampleClass *biggerExampleClass {};&lt;br /&gt;
[...]&lt;br /&gt;
exampleClass       = new CExampleClass      (value1, value2);&lt;br /&gt;
biggerExampleClass = new CBiggerExampleClass(value1, value2);&lt;br /&gt;
[...]&lt;br /&gt;
exampleClass      -&amp;gt;InitExample();&lt;br /&gt;
biggerExampleClass-&amp;gt;InitExample();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Superfluous void ===&lt;br /&gt;
Do not write &amp;lt;code&amp;gt;void&amp;lt;/code&amp;gt; in empty function parameter declarations.&lt;br /&gt;
&lt;br /&gt;
✅ Good:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
void Test();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
❌ Bad:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
void Test(void);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Exceptions to formatting rules ===&lt;br /&gt;
There are some special situations where vertical alignment and longer lines do greatly aid readability, for example the initialization of some table-like multiple row structures. In these &amp;#039;&amp;#039;&amp;#039;rare&amp;#039;&amp;#039;&amp;#039; cases, exceptions can be made to the formatting rules on vertical alignment, and the defined line length may be exceeded as well if it provides an obvious benefit.&lt;br /&gt;
&lt;br /&gt;
The layout can be protected from being reformatted when &amp;lt;code&amp;gt;clang-format&amp;lt;/code&amp;gt; is applied by adding &amp;lt;code&amp;gt;// clang-format off&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;// clang-format on&amp;lt;/code&amp;gt; statements both above and below the lines of code which violate the rules. For example,&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
// clang-format off&lt;br /&gt;
static const CGUIDialogMediaFilter::Filter filterList[] = {&lt;br /&gt;
  { &amp;quot;movies&amp;quot;,       FieldTitle,         556,    SettingType::String,  &amp;quot;edit&amp;quot;,   &amp;quot;string&amp;quot;,   CDatabaseQueryRule::OPERATOR_CONTAINS },&lt;br /&gt;
  { &amp;quot;movies&amp;quot;,       FieldRating,        563,    SettingType::Number,  &amp;quot;range&amp;quot;,  &amp;quot;number&amp;quot;,   CDatabaseQueryRule::OPERATOR_BETWEEN },&lt;br /&gt;
  { &amp;quot;movies&amp;quot;,       FieldUserRating,    38018,  SettingType::Integer, &amp;quot;range&amp;quot;,  &amp;quot;integer&amp;quot;,  CDatabaseQueryRule::OPERATOR_BETWEEN },&lt;br /&gt;
  ...&lt;br /&gt;
  { &amp;quot;songs&amp;quot;,        FieldSource,        39030,  SettingType::List,    &amp;quot;list&amp;quot;,   &amp;quot;string&amp;quot;,   CDatabaseQueryRule::OPERATOR_EQUALS },&lt;br /&gt;
};  &lt;br /&gt;
// clang-format on&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
but the other code guidelines will still need to be applied within the delimited lines of code, and with &amp;lt;code&amp;gt;clang-format&amp;lt;/code&amp;gt; off, care will be needed to enforce these manually. Using vertical alignment means that sometimes the entire block of code may need to be realigned, and good judgement should be used in each case with the objective of preserving readability yet minimizing impact.&lt;br /&gt;
&lt;br /&gt;
This is to be used with discretion; marking large amounts of code to be left unformatted by &amp;lt;code&amp;gt;clang-format&amp;lt;/code&amp;gt; without reasonable justification will result in rejection of the submission.&lt;br /&gt;
&lt;br /&gt;
== Statements ==&lt;br /&gt;
=== Multiple statements ===&lt;br /&gt;
Do not put multiple statements on a single line; always use a new line for a new statement. It is much easier to debug if one can pinpoint a precise line number.&lt;br /&gt;
&lt;br /&gt;
✅ Good:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
std::vector&amp;lt;std::string&amp;gt; test;&lt;br /&gt;
test.push_back(&amp;quot;foobar&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
❌ Bad:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
std::vector&amp;lt;std::string&amp;gt; test; test.push_back(&amp;quot;foobar&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Switch statement default case ===&lt;br /&gt;
In every &amp;lt;code&amp;gt;switch&amp;lt;/code&amp;gt; structure, always include a &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt; case, unless switching on an enum and all enum values are explicitly handled.&lt;br /&gt;
&lt;br /&gt;
== Declarations ==&lt;br /&gt;
=== Multiple declarations ===&lt;br /&gt;
Do not put multiple declarations on a single line, this avoids confusion with differing pointers, references, and initialization values on the same line (cf. [https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es10-declare-one-name-only-per-declaration ISO C++ guidelines]).&lt;br /&gt;
&lt;br /&gt;
✅ Good:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
char* a;&lt;br /&gt;
char b;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
❌ Bad:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
char* a, b;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Pointer and reference types ===&lt;br /&gt;
Left-align &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;&amp;amp;&amp;lt;/code&amp;gt; to the base type they modify.&lt;br /&gt;
&lt;br /&gt;
✅ Good:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
char* a;&lt;br /&gt;
void test(const std::string&amp;amp; b);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
❌ Bad:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
char *a;&lt;br /&gt;
char * b;&lt;br /&gt;
void test(const std::string &amp;amp;b);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is adopted from the HP C++ Coding Guidelines: &amp;lt;blockquote style=&amp;quot;font-size: 1.15em;&amp;quot;&amp;gt;&amp;#039;&amp;#039;The characters &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;&amp;amp;&amp;lt;/code&amp;gt; are to be written with the type of variables instead of with the name of variables in order to emphasize that they are part of the type definition.&amp;#039;&amp;#039;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Const and other modifiers ===&lt;br /&gt;
Place &amp;lt;code&amp;gt;const&amp;lt;/code&amp;gt; and similar modifiers in front of the type they modify.&lt;br /&gt;
&lt;br /&gt;
✅ Good:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
void Test(const std::string&amp;amp; a);&lt;br /&gt;
const int* const someIntPointer;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
❌ Bad:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
void Test(std::string const&amp;amp; a);&lt;br /&gt;
int const * const someIntPointer;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Initialization ===&lt;br /&gt;
Make sure that variables are initialized appropriately at declaration or soon afterwards. This is especially important for fundamental type variables that do not have any constructor. Zero-initialize with &amp;lt;code&amp;gt;{}&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
✅ Good:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
int x{};&lt;br /&gt;
int* y{};&lt;br /&gt;
CLog::Log(&amp;quot;test: {} {}&amp;quot;, x, y);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
❌ Bad:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
int x; // used uninitialized&lt;br /&gt;
int* y = nullptr; // default-initialization not using {}&lt;br /&gt;
CLog::Log(&amp;quot;test: {} {}&amp;quot;, x, y);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In general, prefer the &amp;lt;code&amp;gt;{}&amp;lt;/code&amp;gt; initializer syntax over alternatives. This syntax is less ambiguous and disallows narrowing (cf. [https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-list ISO C++ guidelines]).&lt;br /&gt;
&lt;br /&gt;
✅ Good:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
int x{5};&lt;br /&gt;
int y{x};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scoping ==&lt;br /&gt;
=== Namespaces ===&lt;br /&gt;
Try to put all code into appropriate namespaces (following the directory structure) and avoid polluting the global namespace.&lt;br /&gt;
&lt;br /&gt;
=== Local functions ===&lt;br /&gt;
Put functions local to a compilation unit into an anonymous namespace.&lt;br /&gt;
&lt;br /&gt;
✅ Good:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
namespace&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
void test();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
❌ Bad:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
static void test();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Headers ==&lt;br /&gt;
Included header files have to be sorted (case-sensitively) alphabetically to prevent duplicates and allow better overview, with an empty line clearly separating sections.&lt;br /&gt;
&lt;br /&gt;
The header order has to be:&lt;br /&gt;
* Eponymous header file&lt;br /&gt;
* Platform-independent Kodi includes&lt;br /&gt;
* platform-specific Kodi includes&lt;br /&gt;
* C and C++ system files&lt;br /&gt;
* Other libraries&amp;#039; header files&lt;br /&gt;
* Special Kodi headers (i.e. PlatformDefs.h, system.h and system_gl.h)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;quot;PVRManager.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#include &amp;quot;Application.h&amp;quot;&lt;br /&gt;
#include &amp;quot;ServiceBroker.h&amp;quot;&lt;br /&gt;
#include &amp;quot;addons/AddonInstaller.h&amp;quot;&lt;br /&gt;
#include &amp;quot;dialogs/GUIDialogExtendedProgressBar.h&amp;quot;&lt;br /&gt;
#include &amp;quot;messaging/ApplicationMessenger.h&amp;quot;&lt;br /&gt;
#include &amp;quot;messaging/ThreadMessage.h&amp;quot;&lt;br /&gt;
#include &amp;quot;messaging/helpers/DialogHelper.h&amp;quot;&lt;br /&gt;
#include &amp;quot;music/MusicDatabase.h&amp;quot;&lt;br /&gt;
#include &amp;quot;music/tags/MusicInfoTag.h&amp;quot;&lt;br /&gt;
#include &amp;quot;network/Network.h&amp;quot;&lt;br /&gt;
#include &amp;quot;pvr/addons/PVRClients.h&amp;quot;&lt;br /&gt;
#include &amp;quot;pvr/channels/PVRChannel.h&amp;quot;&lt;br /&gt;
#include &amp;quot;settings/Settings.h&amp;quot;&lt;br /&gt;
#include &amp;quot;threads/SingleLock.h&amp;quot;&lt;br /&gt;
#include &amp;quot;utils/JobManager.h&amp;quot;&lt;br /&gt;
#include &amp;quot;utils/Variant.h&amp;quot;&lt;br /&gt;
#include &amp;quot;utils/log.h&amp;quot;&lt;br /&gt;
#include &amp;quot;video/VideoDatabase.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cassert&amp;gt;&lt;br /&gt;
#include &amp;lt;utility&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;libavutil/pixfmt.h&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the headers aren&amp;#039;t sorted, either do your best to match the existing order, or precede your commit with an alphabetization commit. If possible, avoid including headers in another header. Instead, you can forward-declare the class and use a &amp;lt;code&amp;gt;std::unique_ptr&amp;lt;/code&amp;gt; (or similar):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
class CFileItem;&lt;br /&gt;
&lt;br /&gt;
class Example&lt;br /&gt;
{&lt;br /&gt;
  ...&lt;br /&gt;
  std::unique_ptr&amp;lt;CFileItem&amp;gt; m_fileItem;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Naming ==&lt;br /&gt;
=== Namespaces ===&lt;br /&gt;
Use upper case with underscores.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
namespace KODI&lt;br /&gt;
{&lt;br /&gt;
[...]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constants ===&lt;br /&gt;
Use upper case with underscores.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
constexpr int MY_CONSTANT = 1;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enums ===&lt;br /&gt;
Use PascalCase for the enum name and upper case with underscores for the values.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
enum class Dummy&lt;br /&gt;
{&lt;br /&gt;
  VALUE_X,&lt;br /&gt;
  VALUE_Y&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Interfaces ===&lt;br /&gt;
Use PascalCase and prefix with an uppercase I. The filename has to match the interface name without the prefixed I, like this example from Logger.h:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
class ILogger&lt;br /&gt;
{&lt;br /&gt;
public:&lt;br /&gt;
  virtual void Log(...) = 0;&lt;br /&gt;
  virtual ~ILogger() {}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Classes ===&lt;br /&gt;
Use PascalCase and prefix with an uppercase C. Again, the filename has to match the class name without the prefixed C, as shown here from Logger.cpp:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
class CLogger : public ILogger&lt;br /&gt;
{&lt;br /&gt;
public:&lt;br /&gt;
  void Log(...) override;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Methods ===&lt;br /&gt;
Use PascalCase always, uppercasing the first letter even if the methods are private or protected.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
void MyDummyClass::DoSomething();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
Use CamelCase. Type prefixing (a/k/a Systems Hungarian notation) is discouraged.&lt;br /&gt;
&lt;br /&gt;
==== Member variables ====&lt;br /&gt;
Prefix non-static member variables with &amp;lt;code&amp;gt;m_&amp;lt;/code&amp;gt;. Prefix static member variables with &amp;lt;code&amp;gt;ms_&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
int m_variableA;&lt;br /&gt;
static int ms_variableB;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Global variables ====&lt;br /&gt;
Prefix global variables with &amp;lt;code&amp;gt;g_&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
int g_globalVariableA;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Warning|Avoid use of globals as far as reasonably possible. We generally do not want to introduce new global variables.}}&lt;br /&gt;
&lt;br /&gt;
== Comments ==&lt;br /&gt;
=== General ===&lt;br /&gt;
Use &amp;lt;code&amp;gt;// &amp;lt;/code&amp;gt; for inline single-line and multi-line comments. Use &amp;lt;code&amp;gt;/* */&amp;lt;/code&amp;gt; for the copyright comment at the beginning of the file. SPDX license headers are required for all code files (see example below).&lt;br /&gt;
&lt;br /&gt;
✅ Good:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 *  Copyright (C) 2005-2018 Team Kodi&lt;br /&gt;
 *  This file is part of Kodi - https://kodi.tv&lt;br /&gt;
 *&lt;br /&gt;
 *  SPDX-License-Identifier: GPL-2.0-or-later&lt;br /&gt;
 *  See LICENSES/README.md for more information.&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
// Nice comment&lt;br /&gt;
&lt;br /&gt;
// This can also continue for multiple lines:&lt;br /&gt;
// I am the second line.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
❌ Bad:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
/* A comment */&lt;br /&gt;
//another comment&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Doxygen ===&lt;br /&gt;
New classes and functions are expected to have Doxygen comments describing their purpose, parameters, and behavior in the header file. However, do not describe trivialities - it only adds visual noise. Use the Qt style with an exclamation point (&amp;lt;code&amp;gt;/*! */&amp;lt;/code&amp;gt;) and backslash for doxygen commands (e.g. &amp;lt;code&amp;gt;\brief&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
✅ Good:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
/*!&lt;br /&gt;
 * \brief Splits the given input string using the given delimiter into separate strings.&lt;br /&gt;
 *&lt;br /&gt;
 * If the given input string is empty, nothing will be put into the target iterator.&lt;br /&gt;
 *&lt;br /&gt;
 * \param destination the beginning of the destination range&lt;br /&gt;
 * \param input input string to be split&lt;br /&gt;
 * \param delimiter delimiter to be used to split the input string&lt;br /&gt;
 * \param maxStrings (optional) maximum number of splitted strings&lt;br /&gt;
 * \return output iterator to the element in the destination range one past the last element&lt;br /&gt;
 *         that was put there&lt;br /&gt;
 */&lt;br /&gt;
template&amp;lt;typename OutputIt&amp;gt;&lt;br /&gt;
static OutputIt SplitTo(OutputIt destination, const std::string&amp;amp; input, const std::string&amp;amp; delimiter, unsigned int maxStrings = 0);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
❌ Bad:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
 * @brief Function for documentation purposes (javadoc style)&lt;br /&gt;
 */&lt;br /&gt;
void TestFunction();&lt;br /&gt;
&lt;br /&gt;
void ReallyComplicatedFunction(); // does something really complicated&lt;br /&gt;
&lt;br /&gt;
/*!&lt;br /&gt;
 * \brief Frobnicate a parameter&lt;br /&gt;
 * \param param parameter to frobnicate&lt;br /&gt;
 * \result frobnication result&lt;br /&gt;
 */&lt;br /&gt;
int Frobnicate(int param);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Logging ==&lt;br /&gt;
Use the provided logging function &amp;lt;code&amp;gt;CLog::Log&amp;lt;/code&amp;gt;. Do not log to standard output or standard error using, for example, &amp;lt;code&amp;gt;printf&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;std::cout&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Log&amp;lt;/code&amp;gt; function uses the [https://fmtlib.net/ fmt library] for formatting log messages. Basically, you can use &amp;lt;code&amp;gt;{}&amp;lt;/code&amp;gt; as a placeholder for anything and list the parameters to insert after the message, similar to &amp;lt;code&amp;gt;printf&amp;lt;/code&amp;gt;. See [https://fmtlib.net/latest/syntax.html here] for the detailed syntax, and below for an example.&lt;br /&gt;
&lt;br /&gt;
✅ Good:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
CLog::Log(LOGDEBUG, &amp;quot;Window size: {}x{}&amp;quot;, width, height);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
❌ Bad:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
CLog::Log(LOGWARNING, &amp;quot;Window size: %dx%d&amp;quot;, width, height); // printf-style format strings are possible, but discouraged; also the message does not warrant the warning level&lt;br /&gt;
printf(&amp;quot;Window size: %dx%d&amp;quot;, width, height);&lt;br /&gt;
std::cout &amp;lt;&amp;lt; &amp;quot;Window size: &amp;quot; &amp;lt;&amp;lt; width &amp;lt;&amp;lt; &amp;quot;x&amp;quot; &amp;lt;&amp;lt; height &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The predefined logging levels are &amp;lt;code&amp;gt;DEBUG&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;INFO&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;NOTICE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;WARNING&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ERROR&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;SEVERE&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;FATAL&amp;lt;/code&amp;gt;. Use anything &amp;lt;code&amp;gt;INFO&amp;lt;/code&amp;gt; and above sparingly, since it will be written to the log by default. Too many messages will clutter the log and reduce visibility of important information. &amp;lt;code&amp;gt;DEBUG&amp;lt;/code&amp;gt; messages are only written when debug logging is enabled.&lt;br /&gt;
&lt;br /&gt;
== Classes ==&lt;br /&gt;
=== Member visibility ===&lt;br /&gt;
Make class data members &amp;lt;code&amp;gt;private&amp;lt;/code&amp;gt;. Think twice before using &amp;lt;code&amp;gt;protected&amp;lt;/code&amp;gt; for data members and functions, as its level of encapsulation is effectively equivalent to &amp;lt;code&amp;gt;public&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Const correctness ===&lt;br /&gt;
Try to mark member functions of classes as &amp;lt;code&amp;gt;const&amp;lt;/code&amp;gt; whenever and wherever reasonable.&lt;br /&gt;
&lt;br /&gt;
=== Overriding virtual functions ===&lt;br /&gt;
When overriding virtual functions of a base class, add the &amp;lt;code&amp;gt;override&amp;lt;/code&amp;gt; keyword. Do not add the &amp;lt;code&amp;gt;virtual&amp;lt;/code&amp;gt; keyword.&lt;br /&gt;
&lt;br /&gt;
✅ Good:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
class CLogger : public ILogger&lt;br /&gt;
{&lt;br /&gt;
public:&lt;br /&gt;
  void Log(...) override;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
❌ Bad:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
class CLogger : public ILogger&lt;br /&gt;
{&lt;br /&gt;
public:&lt;br /&gt;
  virtual void Log(...) override;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Default member initialization ===&lt;br /&gt;
Use default member initialization instead of initializer lists or constructor assignments whenever it makes sense.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
{&lt;br /&gt;
  bool bar{false};&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Destructors in interfaces ===&lt;br /&gt;
A class with any virtual functions should have a destructor that is either public and virtual, or else protected and non-virtual (cf. [https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-dtor-virtual ISO C++ guidelines]).&lt;br /&gt;
&lt;br /&gt;
=== Constructor Initialization Lists ===&lt;br /&gt;
For lines up to [[#Line length]], everything stays on one line, excluding the braces, which must be on the adjacent lines in both directions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
MyClass::CMyClass(bool bBoolArg, int iIntegerArg) : m_bArg(bBoolArg), m_iArg(iIntegerArg)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For longer lines, break before a colon and after a comma.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
MyClass::CMyClass(bool bBoolArg,&lt;br /&gt;
                  int iIntegerArg,&lt;br /&gt;
                  const std::string&amp;amp; strSomeText,&lt;br /&gt;
                  const std::shared_ptr&amp;lt;CMyOtherClass&amp;gt;&amp;amp; myOtherClass)&lt;br /&gt;
  : m_bBoolArg(bBoolArg),&lt;br /&gt;
    m_iIntegerArg(iIntegerArg),&lt;br /&gt;
    m_strSomeText(strSomeText),&lt;br /&gt;
    m_myOtherClass(myOtherClass)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Other conventions ==&lt;br /&gt;
=== Output parameters ===&lt;br /&gt;
For functions that have multiple output values, prefer using a &amp;lt;code&amp;gt;struct&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;tuple&amp;lt;/code&amp;gt; return value over output parameters that use pointers or references (cf. [https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-out-multi ISO C++ guidelines]). In general, try to avoid output parameters completely (cf. [https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-out ISO C++ guidelines]), [https://google.github.io/styleguide/cppguide.html#Output_Parameters Google C++ Style Guide]). At the function call site, it is completely invisible that, actually, a reference is being passed and the value might be modified, whereas return semantics make it clear what is happening.&lt;br /&gt;
&lt;br /&gt;
=== Casts ===&lt;br /&gt;
New code has to use C++ style casts and not older C style casts. When modifying existing code, the developer can choose to update it to C++ style casts or leave as is. Whenever a &amp;lt;code&amp;gt;dynamic_cast&amp;lt;/code&amp;gt; is used to cast to a pointer type, the result can be &amp;lt;code&amp;gt;nullptr&amp;lt;/code&amp;gt; and needs to be checked accordingly.&lt;br /&gt;
&lt;br /&gt;
=== NULL vs nullptr ===&lt;br /&gt;
Prefer the use of &amp;lt;code&amp;gt;nullptr&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;nullptr&amp;lt;/code&amp;gt; is a type-safe version and as such, can&amp;#039;t be implicitly converted to &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; or anything else.&lt;br /&gt;
&lt;br /&gt;
=== Auto ===&lt;br /&gt;
Feel free to use &amp;lt;code&amp;gt;auto&amp;lt;/code&amp;gt; wherever it improves readability, which is not as often the case as it may appear prima facie. Good places are iterators, or when dealing with containers, while bad places are in code that expects a certain type that is not immediately clear from the context.&lt;br /&gt;
&lt;br /&gt;
✅ Good:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
auto i = var.begin();&lt;br /&gt;
&lt;br /&gt;
std::vector&amp;lt;CSizeInt&amp;gt; list;&lt;br /&gt;
for (const auto j : list)&lt;br /&gt;
{&lt;br /&gt;
  [...]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
❌ Bad:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
std::map&amp;lt;std::string, std::vector&amp;lt;int&amp;gt;&amp;gt;::iterator i = var.begin();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== For loops ===&lt;br /&gt;
Use range-based &amp;lt;code&amp;gt;for&amp;lt;/code&amp;gt; loops wherever it makes sense. If iterators are used, see above about using [[#Auto]].&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
for (const auto&amp;amp; : var)&lt;br /&gt;
{&lt;br /&gt;
  [...]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Remove &amp;lt;code&amp;gt;const&amp;lt;/code&amp;gt; if the value has to be modified. Do not use references to fundamental types that are not modified.&lt;br /&gt;
&lt;br /&gt;
=== Include guards ===&lt;br /&gt;
Use &amp;lt;code&amp;gt;#pragma once&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
✅ Good:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
#pragma once&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
❌ Bad:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
#ifndef SOME_FILE_H_INCLUDED&lt;br /&gt;
#define SOME_FILE_H_INCLUDED&lt;br /&gt;
[...]&lt;br /&gt;
#endif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Type aliases ===&lt;br /&gt;
Use the C++ &amp;lt;code&amp;gt;using&amp;lt;/code&amp;gt; syntax when aliasing types (highly encouraged when it improves readability).&lt;br /&gt;
&lt;br /&gt;
✅ Good:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
using SizeType = int;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
❌ Bad:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
typedef int SizeType;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Goto ===&lt;br /&gt;
The usage of &amp;lt;code&amp;gt;goto&amp;lt;/code&amp;gt; is discouraged.&lt;br /&gt;
&lt;br /&gt;
=== Macros ===&lt;br /&gt;
Try to avoid using C macros; in many cases, they can be easily substituted with other non-macro constructs.&lt;br /&gt;
&lt;br /&gt;
=== Constexpr ===&lt;br /&gt;
Prefer &amp;lt;code&amp;gt;constexpr&amp;lt;/code&amp;gt; over &amp;lt;code&amp;gt;const&amp;lt;/code&amp;gt; for constants when possible. Try to mark functions &amp;lt;code&amp;gt;constexpr&amp;lt;/code&amp;gt; when reasonable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>RogueScholar</name></author>
	</entry>
</feed>