<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to HOWTO Coding Style</title><link>https://sourceforge.net/p/chessx/wiki/HOWTO%2520Coding%2520Style/</link><description>Recent changes to HOWTO Coding Style</description><atom:link href="https://sourceforge.net/p/chessx/wiki/HOWTO%20Coding%20Style/feed" rel="self"/><language>en</language><lastBuildDate>Sun, 19 Apr 2020 19:24:06 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/chessx/wiki/HOWTO%20Coding%20Style/feed" rel="self" type="application/rss+xml"/><item><title>HOWTO Coding Style modified by Jens Nissen</title><link>https://sourceforge.net/p/chessx/wiki/HOWTO%2520Coding%2520Style/</link><description>&lt;div class="markdown_content"&gt;&lt;h1 id="coding-standards"&gt;Coding Standards&lt;/h1&gt;
&lt;p&gt;The ChessX project has a set of coding standards to help improve the consistency and readability of the code. The standards are based on the Qt coding style. If in doubt try to follow the Qt way of doing things. The guidelines are as follows:&lt;/p&gt;
&lt;h1 id="class-names"&gt;Class names&lt;/h1&gt;
&lt;p&gt;Each word in a class name should begin with an uppercase letter, eg. Board, PlayerDatabase.&lt;/p&gt;
&lt;h1 id="class-methods"&gt;Class methods&lt;/h1&gt;
&lt;p&gt;Method names should start with a lower case letter for the first word, with any following words capitalised, eg. count(), doStandardMove(). For methods that represent common actions try to use Qt conventions, eg. if your class is a collection, use count() to return the number of elements.&lt;/p&gt;
&lt;h1 id="class-properties"&gt;Class properties&lt;/h1&gt;
&lt;p&gt;Class properties should always be private or protected. A pair of accessor functions should be created for each property that should be visible. The name of the property itself should start with "m_". For example, this is a code snippet for a property "foo" of "fooType":&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="kd"&gt;public&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
  &lt;span class="n"&gt;fooType&lt;/span&gt; &lt;span class="n"&gt;foo&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="kc"&gt;void&lt;/span&gt; &lt;span class="n"&gt;setFoo&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;fooType&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;private&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
  &lt;span class="n"&gt;fooType&lt;/span&gt; &lt;span class="n"&gt;m_foo&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;If the property is a boolean, use the form "isSomething()" for the "getting" function.&lt;/p&gt;
&lt;h1 id="consts"&gt;Consts&lt;/h1&gt;
&lt;p&gt;Methods that do not alter the state of a class should be made const. Non-primitive arguments should be passed as const references, eg. foo(const ClassName&amp;amp; c).&lt;/p&gt;
&lt;h1 id="enumerated-types"&gt;Enumerated types&lt;/h1&gt;
&lt;p&gt;Enumerated values should start with an uppercase letter, eg. enum Piece {King, Queen, Rook, Bishop, Knight, Pawn};&lt;/p&gt;
&lt;h1 id="bools-and-flags"&gt;Bools and Flags&lt;/h1&gt;
&lt;p&gt;It is recommended to use flags rather than bools for APIs, as this aids readability. For example:&lt;/p&gt;
&lt;p&gt;With a bool parameter:&lt;/p&gt;
&lt;p&gt;findPlayers(prefix, 1000, false)&lt;/p&gt;
&lt;p&gt;With an enumerated type:&lt;/p&gt;
&lt;p&gt;findPlayers(prefix, 1000, PlayerDatabase::IgnoreCase)&lt;/p&gt;
&lt;p&gt;When the parameter is a bool, it is unclear what the false means. However, when an enumerated type is used, its meaning is obvious.&lt;/p&gt;
&lt;h1 id="code-formatting"&gt;Code formatting&lt;/h1&gt;
&lt;p&gt;Tabs should be used for indentation. Opening parenthesis after if or while blocks should be placed in the next new line and closing one should be put in a new line.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt; 
{
  &lt;span class="nv"&gt;doSomethingElse&lt;/span&gt;&lt;span class="ss"&gt;()&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
}
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Easy way to format files accordingly to our formatting policy is to use astyle with following parameters:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt; &lt;span class="n"&gt;astyle&lt;/span&gt; &lt;span class="c1"&gt;--recursive --suffix=none --style=allman --mode=c --indent=spaces=4 --add-brackets --unpad-paren --pad-oper ./*.cpp ./*.h&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jens Nissen</dc:creator><pubDate>Sun, 19 Apr 2020 19:24:06 -0000</pubDate><guid>https://sourceforge.net5a528939c0872580318823677fe07cae3ad246f7</guid></item></channel></rss>