-
Notifications
You must be signed in to change notification settings - Fork 1
/
CODING_STYLE.txt
93 lines (75 loc) · 3.14 KB
/
CODING_STYLE.txt
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
This file contains the FEI coding style.
Note that this coding style specifically includes only *style* guidelines,
in other words, stuff that could be considered completely arbitrary. In most
cases you could argue for a different style that would be just as correct.
Conventional wisdom says that no particular coding style is better than any
other, but it is important to have one. It is easier to read and maintain a
code base which uses a consistent style.
(Since this coding style was adopted fairly late in FEI's development, some
FEI implementation code doesn't completely conform...)
Here is the FEI coding style:
* Indenting: 2 spaces
* Class names
Start with upper-case letter, and each word in multi-word names starts
with upper-case letter.
Example: class LinearSystem {
* Function/Method names
Start with lower-case letter, each subsequent word in multi-word names
starts with upper-case letter.
Example: int getGlobalIndex(
* Private class member-variable names
Start with lower-case letter, each subsequent word in multi-word names
starts with upper-case letter. Class member-variable names always end
with an underscore.
Example: int ownerProc_;
* Function/Method declarations
First argument on the same line as function/method name, subsequent
arguments one per line, all arguments indented to same depth.
Example: int method(int arg1,
int arg2);
* Function/Method definitions
- Opening/closing curly-braces on a line by themselves.
- No code or comment to extend past 80th column.
- Function/method invocations may have multiple arguments per line;
if more than one line required then arguments on subsequent lines
are indented to the the same depth as arguments on the first line.
Example:
int ClassName::methodName(int arg1,
int arg2,
int arg3,
int arg4,
int& arg5)
{
int err = function(arg1, arg2, arg3,
arg4, arg5);
return(err);
}
* Header include-guards
For a header named 'filename.hpp', the include-guard macro
is '_filename_hpp_'.
* if,while,for blocks ALWAYS have curly brackets, even if the block only
contains one statement.
Example:
if (condition) {
statement;
}
//don't omit brackets like this:
if (condition)
statement;
* Inline methods
Methods to be inlined are declared inside class declaration, then
the implementation is provided in the header, below the class declaration,
with the inline keyword.
Example:
class ClassName {
int method();
};
inline int ClassName::method()
{
//statements
}
* Templates
Templates, including function templates and class templates, are fully
implemented in headers except for explicit instantiations and
specializations. Explicit instantiations can be placed in source (.cpp)
files.