-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCODING_STANDARDS
101 lines (65 loc) · 2.28 KB
/
CODING_STANDARDS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
This document documnent describes the Catalanitzador coding standards
--- Naming
* For Classes, interfaces, enums and structures use UpperCamelCase
For example:
class SystemRestore
* For variables and variales we use LowerCamelCase
For example:
int systemRestore
Prefixes:
- 'm_' to indicate member variable such as 'm_processes'
- 'g_' to indicate that is a global variable 'g_currentObject'
* For methods, if they are public we use UpperCamelCase and if they are private
or protected the prefix with '_' with LowerCamelCase
For example:
public:
void FinishExecution(ExecutionProcess process);
protected:
void _enumVersions(vector <wstring>& versions);
* For constants, we use UPPER case, for example:
#define APPLICATON_WEBSITE L"http://catalanitzador.softcatala.org"
--- Declaring and initializing
* Declare the constants and macros at the beginning of the .cpp files.
* Initialize all arrays to a default value, specially initialize char and wchar_t arrays to 0.
The compiler initializes automatically for us in debug mode but in release mode it doesn't.
These is a common source of mistakes.
For example:
char szTmpA[1024] = {0};
wchar_t szTmpB[1024] = {0};
--- Namespaces
* You should avoid using namespace std in general because it can cause problems when using different libraries.
For example:
// <vector>
namespace std
{
template < class T, class Allocator = allocator<T> >
class vector // STL vector
{
// ...
};
}
// "mylib.h"
template < class T >
class vector // my own vector
{
// ...
};
// file.cpp
#include <vector>
#include "mylib.h"
int main()
{
vecor < int > x; // my own vector ( mylib.h doesn't define any namespace )
using namespace std;
vecor < int > y; // which vector? it's ambiguous now that bot vectors can be found in the global namespace
}
You should particularly avoid using in header files as every other file which will #include them will get this issue.
Instead restrict to the specified symbols or use explicit namespace scope as follows:
For example:
using std::cout;
using std::vector; // as above, restricted to the specified symbols
cout << "blah blah";
vector<int> v(10);
or better:
std::cout << "blah blah"; // explicit namespace scope
std::vector<int> v(10);