forked from PetaVision/OpenPV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyleguide
95 lines (67 loc) · 2.75 KB
/
styleguide
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
//********************************
// PetaVision style guide
//********************************
// Variable names are camelCase
// Class, Struct, and Enum type names are PascalCase
// Primitive type names are lowercase
// Enum values are ALL_CAPS
// TODO comments must always include the date entered
// Descriptive variable names are preferred to shorthand.
// Avoid using one letter abbreviations anywhere other than for loop indices.
// Good:
int xIndex = 0;
// Acceptable:
int xInd = 0;
// Bad:
int xi = 0;
// Member variables start with a lowercase m and are PascalCase afterward.
char* mFileName = nullptr;
// Use C++11 standards wherever applicable.
// Favor standard containers over malloc or new.
// Recommended:
std::vector<float> _buffer;
_buffer.reserve(_numNeurons);
HyPerLayer* mPostLayer = nullptr;
int value = static_cast<int>(1.5f);
// Not recommended:
float* _buffer = calloc(mNumNeurons, sizeof(float));
HyPerLayer* mPostLayer = NULL;
int value = (int)1.5f;
// One-line getters and setters live in .hpp files.
// Getters and setters should always be named getVariableName() and setVariableName().
// Functions should appear in the cpp file in the same order as the hpp file
// .hpp files should be ordered in the following manner
// Parameter Functions
// Constructors / Destructor
// Public Functions
// Protected Functions
// Private Functions
// Public Variables (these should be very rare, if any)
// Protected Variables
// Private Variables
// Getters and Setters
// Factory Function
// Within these sections, members should be ordered alphabetically by type.
// Reference types come after value types.
// Any variables or functions that require the same preprocessor directive,
// such as PV_USE_CUDA, should appear after the functions or variables that
// do not require it. Each section listed above should only have one ifdef
// for any given flag.
// All whitespace should be spaces (no tabs).
// New scope should be indented by 3 spaces.
// The opening brace for a new scope should be on the same line as the previous statement.
// If the contained statement is small enough to fit on the same line along with the closing
// bracket, it can be on the same line.
// Nested #ifdefs should use spaces to indent between the # and the ifdef.
#ifdef PV_USE_CUDA
// Do something
# ifdef PV_USE_CUDNN
// Do something else
# else
// Do another thing
# endif
#endif
// No inactive code. If a block of code needs to be commented out or marked #ifdef OBSOLETE,
// it should be removed with a comment indicating the date of removal and the reason. If
// this code needs to be referred to in the future it can be found in the appropriate commit
// based on the date of removal.