<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://maemo.octonezd.me/index.php?action=history&amp;feed=atom&amp;title=Miniature%2FDevelopment%2FCodingStyle</id>
	<title>Miniature/Development/CodingStyle - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://maemo.octonezd.me/index.php?action=history&amp;feed=atom&amp;title=Miniature%2FDevelopment%2FCodingStyle"/>
	<link rel="alternate" type="text/html" href="https://maemo.octonezd.me/index.php?title=Miniature/Development/CodingStyle&amp;action=history"/>
	<updated>2026-04-22T00:16:11Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://maemo.octonezd.me/index.php?title=Miniature/Development/CodingStyle&amp;diff=26431&amp;oldid=prev</id>
		<title>imported_&gt;mikhas: /* General */</title>
		<link rel="alternate" type="text/html" href="https://maemo.octonezd.me/index.php?title=Miniature/Development/CodingStyle&amp;diff=26431&amp;oldid=prev"/>
		<updated>2011-09-03T11:11:32Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;General&lt;/span&gt;&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 11:11, 3 September 2011&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-l7&quot;&gt;Line 7:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 7:&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;* Type names are in CamelCase&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;* Type names are in CamelCase&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;* Method names are in mixedCase (= lowerCamelCase).&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;* Method names are in mixedCase (= lowerCamelCase).&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;* Opening braces for code blocks &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;after &lt;/del&gt;newlines, *except* opening braces for classes and methods.&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;* Opening braces for code blocks &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;before &lt;/ins&gt;newlines, *except* opening braces for classes and methods.&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;* Variables use under_scores and are lower_cases, to make them stand out from other symbols.&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;* Variables use under_scores and are lower_cases, to make them stand out from other symbols.&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;** Member variables are prefixed with &amp;quot;m_*&amp;quot; if there is no private data class (PIMPL). In the latter case, &amp;quot;d-&amp;gt;&amp;quot; already serves as a prefix. In the same sense, member variables in *Private classes have no prefix at all.&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;** Member variables are prefixed with &amp;quot;m_*&amp;quot; if there is no private data class (PIMPL). In the latter case, &amp;quot;d-&amp;gt;&amp;quot; already serves as a prefix. In the same sense, member variables in *Private classes have no prefix at all.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key my_wiki:diff:1.41:old-26432:rev-26431:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>imported_&gt;mikhas</name></author>
	</entry>
	<entry>
		<id>https://maemo.octonezd.me/index.php?title=Miniature/Development/CodingStyle&amp;diff=26432&amp;oldid=prev</id>
		<title>imported_&gt;mikhas: New page: {{Miniature}} = General = We mostly &lt;s&gt;try to follow the offical Qt Coding Guidelines, but with some exceptions.&lt;/s&gt; follow mikhas&#039; personal coding style for Qt: * We use whitespaces over ...</title>
		<link rel="alternate" type="text/html" href="https://maemo.octonezd.me/index.php?title=Miniature/Development/CodingStyle&amp;diff=26432&amp;oldid=prev"/>
		<updated>2011-08-27T19:00:17Z</updated>

		<summary type="html">&lt;p&gt;New page: {{Miniature}} = General = We mostly &amp;lt;s&amp;gt;try to follow the offical Qt Coding Guidelines, but with some exceptions.&amp;lt;/s&amp;gt; follow mikhas&amp;#039; personal coding style for Qt: * We use whitespaces over ...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Miniature}}&lt;br /&gt;
= General =&lt;br /&gt;
We mostly &amp;lt;s&amp;gt;try to follow the offical Qt Coding Guidelines, but with some exceptions.&amp;lt;/s&amp;gt; follow mikhas&amp;#039; personal coding style for Qt:&lt;br /&gt;
* We use whitespaces over tabs.&lt;br /&gt;
* Max. length of a source code line is 120 characters.&lt;br /&gt;
* We use (nested) namespaces.&lt;br /&gt;
* Type names are in CamelCase&lt;br /&gt;
* Method names are in mixedCase (= lowerCamelCase).&lt;br /&gt;
* Opening braces for code blocks after newlines, *except* opening braces for classes and methods.&lt;br /&gt;
* Variables use under_scores and are lower_cases, to make them stand out from other symbols.&lt;br /&gt;
** Member variables are prefixed with &amp;quot;m_*&amp;quot; if there is no private data class (PIMPL). In the latter case, &amp;quot;d-&amp;gt;&amp;quot; already serves as a prefix. In the same sense, member variables in *Private classes have no prefix at all.&lt;br /&gt;
* Use initializer list and call construct each member explicitly.&lt;br /&gt;
* No boolean method parameters, unless it&amp;#039;s a boolean property. Use enums instead.&lt;br /&gt;
* Use Q_SLOT, Q_SIGNAL as a method prefix.&lt;br /&gt;
* Impl files have a .cc extensions, header files use .h&lt;br /&gt;
* Use Qt containers over std containers.&lt;br /&gt;
* No explicit delete statements. Use QScopedPointer or C++&amp;#039;s inbuilt resource cleanup of member variables.&lt;br /&gt;
* Avoid QObject parent ownership - with C++ inbuilt mechanism, smart pointers and the concept of RAII, there is rarely need for it. It makes memory management more explicit and avoids another constant source of bugs.&lt;br /&gt;
** Try to use copyable value types instead of full-blown QObjects.&lt;br /&gt;
* Avoid singletons&lt;br /&gt;
** Singletons often become hidden dependencies of a class, making the class less reusable, as it increases coupling.&lt;br /&gt;
** Prefer dependency injection instead, this also increases testability.&lt;br /&gt;
* Public methods should be virtual.&lt;br /&gt;
** Makes classes easier to reuse, increases testability.&lt;br /&gt;
** Does not apply for structs.&lt;br /&gt;
&lt;br /&gt;
= Naming conventions =&lt;br /&gt;
&lt;br /&gt;
* Methods *do* something, that&amp;#039;s why their names should always contain a verb (slots and signals count as methods, too).&lt;br /&gt;
&lt;br /&gt;
    connect(this,  SIGNAL(someSignalChanged()),&lt;br /&gt;
            other, SLOT(onSomeSignalChanged()));&lt;br /&gt;
&lt;br /&gt;
* typedef&amp;#039;d types *might* hint at their composed types (to emphasize their intended use), but avoid directly including the type information in the name:&lt;br /&gt;
&lt;br /&gt;
  typedef QSharedPointer&amp;lt;SomeClass&amp;gt; SomeSharedClass; // Good! Sharing a resource is a concept.&lt;br /&gt;
  typedef QSharedPointer&amp;lt;SomeClass&amp;gt; SomeClassPtr; // Bad! What is a &amp;quot;SomeClassPtr *some_variable&amp;quot; now?&lt;br /&gt;
&lt;br /&gt;
  typedef QList&amp;lt;SomeClass&amp;gt; SomeClassList; // still OK, since &amp;quot;List&amp;quot; is a concept, too.&lt;br /&gt;
&lt;br /&gt;
* Avoid hungarian variable names.&lt;br /&gt;
* If in doubt, name slot &amp;quot;onSomeSignalChanged&amp;quot;. This makes for nice connection code:&lt;br /&gt;
&lt;br /&gt;
  connect(some_signal_source, SIGNAL(theSignalWasEmitted()),&lt;br /&gt;
          some_receiver,      SLOT(onTheSignalWasEmitted()),&lt;br /&gt;
          Qt::UniqueConnection);&lt;br /&gt;
&lt;br /&gt;
** Use normalized signal/slot signatures (no const keyword, no &amp;amp;).&lt;br /&gt;
&lt;br /&gt;
= Advanced =&lt;br /&gt;
* Method parameters should be easy to read:&lt;br /&gt;
&lt;br /&gt;
  class SomeClass&lt;br /&gt;
  {&lt;br /&gt;
      void someMethod(SomeType arg1,&lt;br /&gt;
                      SomeOtherType arg2,&lt;br /&gt;
                      ...);&lt;br /&gt;
&lt;br /&gt;
** Details:&lt;br /&gt;
*** Move each argument to a new line. This serves two goals: header files will be easier to scan (for humans), and you&amp;#039;ll spot those ugly methods that scream &amp;quot;refactor me!&amp;quot; faster because they have more than 3 arguments. Also, because it *is* ugly, you might just go and refactor it, which will help everyone.&lt;br /&gt;
&lt;br /&gt;
* Use const refs for arguments when possible, even if the type is COW (copy-on-write, for example QString).&lt;br /&gt;
&lt;br /&gt;
* Don&amp;#039;t return const refs for value types. Leave the decision to the caller.&lt;br /&gt;
&lt;br /&gt;
* Conditionals&lt;br /&gt;
&lt;br /&gt;
  if ((something &amp;amp;&amp;amp; somethingElse)&lt;br /&gt;
       || orPerhapsThis) {&lt;br /&gt;
      ...&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
** Details:&lt;br /&gt;
*** Conditionals often contain bugs. Especially when the surrounding code gets refactored, those bugs simply slip in.&lt;br /&gt;
*** If a conditional needs to be wrapped, it starts to look ugly. Good! It might lead you to refactor the code, moving the condition itself into a predicate function (which has the nice effect to serve as a comment, if it has a good name).&lt;br /&gt;
*** Nested conditionals quickly start to look ugly with all those line separators, but you probably guessed it already: It&amp;#039;s just another sign that this code might need some cleanup! Nested conditionals should be used rarely or hidden within dedicated methods.&lt;br /&gt;
&lt;br /&gt;
* One space after keywords that could be mistaken as functions (if, for, ...).&lt;br /&gt;
&lt;br /&gt;
* If you store a pointer to an object over which you do not intend to take ownership, then wrap this pointer in a QWeakPointer:&lt;br /&gt;
&lt;br /&gt;
  class SomeOtherClass&lt;br /&gt;
  {&lt;br /&gt;
      QWeakPointer&amp;lt;SomeType&amp;gt; m_member;&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
** Details:&lt;br /&gt;
*** QWeakPointers keep track of QObject deletion and set all referring QWeakPointers to zero, preventing dangling pointers. Especially when using signals &amp;amp; slots, this is an often (and sometimes hard to spot!) source of bugs. With QWeakPointers, you can wrap your code with conditional guards like so:&lt;br /&gt;
&lt;br /&gt;
  if (SomeType *var = m_member.data()) {&lt;br /&gt;
      // Do sth with var&lt;br /&gt;
      // This block *never* gets executed even if m_member was deleted elsewhere.&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
* Assign 0 to pointers after deletion (or use QPointers).&lt;br /&gt;
* Always initialize type primitives (e.g., pointers) in the constructor&amp;#039;s initializer list.&lt;br /&gt;
* Don&amp;#039;t use forward declaration unless necessary. It is not your task to optimize the compiler. Also, Qt Creator gets confused by them.&lt;br /&gt;
&lt;br /&gt;
== How to keep code testable (and hopefully, mostly bugfree) ==&lt;br /&gt;
We want to have testable code, therefore we also want to follow some advanced coding standards.&lt;br /&gt;
&lt;br /&gt;
For that, I will try to list some really really useful advice from this document: http://www.research.att.com/~bs/JSF-AV-rules.pdf, a coding style document for C++. Bjarne Stroustrup worked on that one, yes.&lt;br /&gt;
 &lt;br /&gt;
* Keep methods at a reasonable length. In general: If it doesn&amp;#039;t fit on a screen page it&amp;#039;s probably too long. More precise: Every method longer than 200 lines of code (including comments, yes) is too long.&lt;br /&gt;
* Within a method, avoid a cyclomatic complexity higher than 20 (see Appendix A regarding AV Rule 3, pp. 65, &amp;quot;Cyclomatic complexity measures the amount of decision logic in a single software module.&amp;quot;, and the example).&lt;br /&gt;
* Avoid cyclic dependencies between classes/modules (Rationale: it&amp;#039;s mostly an indicator for layer violations).&lt;/div&gt;</summary>
		<author><name>imported_&gt;mikhas</name></author>
	</entry>
</feed>