forked from sumatrapdfreader/sumatrapdf
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodingstyle.txt
More file actions
85 lines (61 loc) · 2.01 KB
/
codingstyle.txt
File metadata and controls
85 lines (61 loc) · 2.01 KB
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
Over time Sumatra accrued code using different naming styles.
Let's fix that.
This document describes the naming style we should use in
future code (and, as a low priority, convert existing code
to that style).
Coding styles are always controversial because they are mostly
a matter of opinion.
This coding style follows 2 main principles:
* codify the style that is already used frequently in Sumatra
* clean looking code (which is e.g. why we avoid "_" prefixes or postfixes in names)
1. Naming classes, methods, functions, variables
------------------------------------------------
The best way to describe naming style is via examples.
struct ThisIsStruct
{
bool firstMember;
int second;
char seeHowWeAlignNames;
};
class ThisIsClass
{
bool firstDataMember;
int second;
bool ThisIsMethod(int inArgsGoFirst, WCHAR *outArgsGoLast);
};
bool ThisIsFunction(int inArgsGoFirst, int *outArgsGoLast)
{
bool variableName = true;
*outArgsGoLast = 5;
return variableName;
}
int gThisIsGlobalVariable;
2. Tabs vs. spaces
------------------
We use spaces, not tabs, with 4 space indentation.
3. Naming of header guards
--------------------------
We use Webkit's style:
"#define, #ifdef "header guards" should be named exactly the same as the file (
including case), replacing the '.' with a '_'."
http://www.webkit.org/coding/coding-style.html
4. #include statements
----------------------
.cpp files:
- #include "BaseUtil.h" first
- followed by .h corresponding to .cpp i.e. Foo.cpp => #include "Foo.h"
- followed by system headers (C library, additional windows headers)
- followed by .h for Sumatra's files, sorted by name
- as an exception to the "sort by name" rule, #include "DebugLog.h"
can be at the end
.h files:
- should never include "BaseUtil.h"
- need to include all the .h files they depend on, although it's preferred
to use pointers in APIs and pre-declaring types i.e.:
// Bar.h
class Foo;
void Bar(Foo *);
is better than:
// Bar.h
#include "Foo.h"
void Bar(Foo& );