Merge pull request #4150 from glassez/coding_style

Improve CODING_GUIDELINES.md.
This commit is contained in:
sledgehammer999 2015-11-23 10:19:50 -06:00
commit 23748547a2

View file

@ -10,18 +10,20 @@ int myFunction(int a)
//code //code
} }
myClass::myClass(int *parent) void myFunction() {} // empty body
MyClass::MyClass(int *parent)
: m_parent(parent) : m_parent(parent)
{ {
//initialize //initialize
} }
int myClass::myMethod(int a) int MyClass::myMethod(int a)
{ {
//code //code
} }
class myOtherClass class MyOtherClass
{ {
public: public:
//code //code
@ -31,10 +33,18 @@ private:
//code //code
}; };
namespace id namespace Name
{ {
//code //code
} }
// Lambdas
[](int arg1, int arg2) -> bool { return arg1 < arg2; }
[this](int arg)
{
this->acc += arg;
}
``` ```
#### b. Other code blocks #### #### b. Other code blocks ####
@ -75,6 +85,12 @@ default:
} }
``` ```
#### d. single-line blocks (lambdas, initializer lists etc.) ####
```c++
{} // empty - space before {
{ body } // spaces around { and before }
```
### 2. If blocks ### ### 2. If blocks ###
#### a. Multiple tests #### #### a. Multiple tests ####
```c++ ```c++
@ -125,10 +141,10 @@ UTF-8 and Unix-like line ending (LF). Unless some platform specific files need o
Initialization lists should be vertical. This will allow for more easily readable diffs. The initialization colon should be indented and in its own line along with first argument. The rest of the arguments should be indented too and have the comma prepended. Initialization lists should be vertical. This will allow for more easily readable diffs. The initialization colon should be indented and in its own line along with first argument. The rest of the arguments should be indented too and have the comma prepended.
```c++ ```c++
myClass::myClass(int a, int b, int c, int d) myClass::myClass(int a, int b, int c, int d)
: priv_a(a) : m_a(a)
, priv_b(b) , m_b(b)
, priv_c(c) , m_c(c)
, priv_d(d) , m_d(d)
{ {
//code //code
} }
@ -137,7 +153,7 @@ myClass::myClass(int a, int b, int c, int d)
### 6. Enums.### ### 6. Enums.###
Enums should be vertical. This will allow for more easily readable diffs. The members should be indented. Enums should be vertical. This will allow for more easily readable diffs. The members should be indented.
```c++ ```c++
enum days enum Days
{ {
Monday, Monday,
Tuesday, Tuesday,
@ -149,7 +165,41 @@ enum days
}; };
``` ```
### 7. Misc.### ### 7. Names.###
All names should be camelCased.
#### a. Type names and namespaces ####
Type names and namespaces start with Upper case letter (except POD types).
```c++
class ClassName {}
struct StructName {}
enum EnumName {}
typedef QList<ClassName> SomeList;
namespace NamespaceName
{
}
```
#### b. Variable names ####
Variable names start with lower case letter.
```c++
int myVar;
```
#### c. Private member variable names ####
Private member variable names start with lower case letter and should have ```m_``` prefix.
```c++
class MyClass
{
int m_myVar;
}
```
### 8. Misc.###
* Line breaks for long lines with operation: * Line breaks for long lines with operation: