forked from tsadigovAgmail/ctpp
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCodeStyle
145 lines (110 loc) · 3.94 KB
/
CodeStyle
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
CodeStyle -- CTPP2 source file style guide. Based on FreeBSD style(9).
This file describes coding rules for CTPP2 header and source files.
This is also a preferred style for source code of all applications written in C++.
0. The copyright header should be a multi-line comment, with the first line
of the comment having a dash after the star like so:
/*-
* Copyright (c) 2004 - 2010 CTPP Team
*
* Long, boring license goes here, but redacted for brevity
*/
1. All classes, structures and data fields
MUST have auto-documentation in doxygen style
/**
@doxytag
@brief Auto-documentation for doxygen
*/
class SomeClass
{
....
};
/** @brief Some Variable */
INT_32 iSomeVariable;
2. Important and BIG comments SHOULD be in C-style
/*
* VERY Important single-line comment.
*/
/*
* VERY BIG multi-line comment.
*
* blah-blah blah-blah blah-blah blah-blah blah-blah
* blah-blah blah-blah blah-blah blah-blah blah-blah
* blah-blah blah-blah blah-blah blah-blah blah-blah
*/
3. Single-line comments SHOULD be in C++ Style
// Single-line comment
4. NEVER use "standard" types. Use instead platform-independent
types, described in CTPP2Types.h
5. If it is possible, don't use boost and other foreign libraries.
Boost, etc - good and powerful libraries, BUT non-compartible in most
architectures and compilers.
6. All platform-dependent typedefs MUST be placed into file Types.h
7. All defines MUST be placed into file GlobalDefines.h
8. Enumeration values are all uppercase. Enumeration name SHOULD start from lowercase 'e'
enum eMyEnum { ONE, TWO .... }
In declarations, do not put any whitespace between asterisks and adjacent
tokens, except for tokens that are identifiers related to types.
9. Names of structures and classes are in mixed case, instances delimited by changed case.
struct FooBar
{
INT_32 some_field;
INT_64 other_field;
};
9. When declaring variables in structures, declare them sorted by use, then
by size (largest to smallest), and then in alphabetical order.
Variables in structures all lowercase, instances delimited by understrike '_'
10. When declaring variables in classes, declare them sorted by use, then
by size (largest to smallest), and then in alphabetical order.
Variables in classes are in mixed case. Instances delimited by changed case.
class BarBaz
{
public:
BarBaz();
~BarBaz() throw();
private:
INT_32 iSomeVariable;
INT_64 iOtherVariable;
};
11. All destructors SHOULD have empty list of exceptions.
class BarBaz
{
public:
~BarBaz() throw();
};
12. NEVER use public variables in classes.
NEVER use private and protected variables in structures
13. NEVER use assert macros.
Assert, in depends of compiler flags changes behavior of programm.
Therefore, programm that compiled with debug option IS NOT the same
as a programm without them.
Use instead exceptions.
14. Do not use "!" for tests unless it is a boolean, e.g. use
if (*p == '\0')
not:
if (!*p)
15. All branches and loops MUST use braces (`{' and `}'), e.g. use
for (;;) { stmt; }
not:
for (;;) stmt;
16. For infinite loops use for (;;), not while(true)
17. Indentation is an tab (0x09) and space (0x20).
Use tabs ONLY in string prefixies, use spaces ONLY in string suffixes, e.g. use
class BarBaz
{
>> INT_32........iVariable;
public:
>> inline BarBaz()
>> {
>> >> stmt;
>> }
};
struct FooBar
{
>> INT_32........var_1;
>> INT_32........var_2;
>> CCHAR_P.......some_data;
};
where `.' - space and `>>' - tab
18. Sources MUST be compiled without warnings with "-Wall -pedantic -wno-long-long"
GNU gcc code checker flags or its analogs in other compilers.
19. Examples: examples/code/Skel.*