Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
dev:dg_code_style_guide [2017/09/13 08:48] – [Naming] devadev:dg_code_style_guide [2024/07/26 10:46] (current) – [Classes] deva
Line 3: Line 3:
 | **//Code is written once by one person but read many times by many people.//** | | **//Code is written once by one person but read many times by many people.//** |
  
-What this essentially boils down to is; don't make syntactic short-cuts that makes it easier to write the code if it makes it harder to read the the code.+What this essentially boils down to is; don't make syntactic short-cuts that makes it easier to write the code if it makes it harder to read the code.
  
 Always write comments to logical blocks in the code that explains for example what a for loop does or how a couple of function calls interact. Always write comments to logical blocks in the code that explains for example what a for loop does or how a couple of function calls interact.
Line 15: Line 15:
 =====Curly Braces===== =====Curly Braces=====
 Use [[https://en.wikipedia.org/wiki/Indent_style#Allman_style|BSD/Allman style]]. Use [[https://en.wikipedia.org/wiki/Indent_style#Allman_style|BSD/Allman style]].
-This basically boils down to 'curly braces always on a new line' with the only exception being switch statements (see later section) as this:+This basically boils down to 'curly braces always on a new line':
 <code c++> <code c++>
 namespace Foo namespace Foo
Line 122: Line 122:
 }; };
 </code> </code>
 +
 +Member variables should always be initialized in the header file, and should use the curly-brace notation:
 +<code c++>
 +class MyClass
 +{
 +private:
 +  int some_member_variable{}; // default initialize to 0
 +  int start_position{42}; // default value decided by the developer
 +  static constexpr int step_size{2}; // and use static constexpr whenever possible instead of defines
 +  std::array<int, 5> buckets{}; // default initializes all values at once
 +};
 +</code>
 +
 =====Pointers and References===== =====Pointers and References=====
 Pointer stars and reference ampersands must be placed to the left without space after the type: Pointer stars and reference ampersands must be placed to the left without space after the type:
Line 234: Line 247:
 //defines//: //defines//:
 <code c++> <code c++>
-#define ALL_UPPERCASE_WITH_UNDERSCORES 42+#define SHOUTING_SNAKE_CASE 42
 </code> </code>
  
Line 263: Line 276:
   //! This is a method.   //! This is a method.
   //! \param foo The foo argument is an integer.   //! \param foo The foo argument is an integer.
-  //! \param bar The bar argument is a boolan.+  //! \param bar The bar argument is a boolean.
   //! \return This method returns a float.   //! \return This method returns a float.
   float method(int foo, bool bar);   float method(int foo, bool bar);
dev/dg_code_style_guide.1505285313.txt.gz · Last modified: 2017/09/13 08:48 by deva
Trace:
GNU Free Documentation License 1.3
Valid CSS Driven by DokuWiki Recent changes RSS feed Valid XHTML 1.0