@@ -32,11 +32,11 @@ these rules:
32
32
33
33
## Formatting
34
34
35
- ## Left-leaning (C++ style) asterisks for pointer declarations
35
+ ### Left-leaning (C++ style) asterisks for pointer declarations
36
36
37
37
` char* buffer; ` instead of ` char *buffer; `
38
38
39
- ## C++ style comments
39
+ ### C++ style comments
40
40
41
41
Use C++ style comments (` // ` ) for both single-line and multi-line comments.
42
42
Comments should also start with uppercase and finish with a dot.
@@ -56,7 +56,7 @@ preferred style. Feel free to update old comments to the preferred style when
56
56
working on code in the immediate vicinity or when changing/improving those
57
57
comments.
58
58
59
- ## 2 spaces of indentation for blocks or bodies of conditionals
59
+ ### 2 spaces of indentation for blocks or bodies of conditionals
60
60
61
61
``` c++
62
62
if (foo)
@@ -76,7 +76,7 @@ Braces are optional if the statement body only has one line.
76
76
77
77
` namespace ` s receive no indentation on their own.
78
78
79
- ## 4 spaces of indentation for statement continuations
79
+ ### 4 spaces of indentation for statement continuations
80
80
81
81
``` c++
82
82
VeryLongTypeName very_long_result = SomeValueWithAVeryLongName +
@@ -85,7 +85,7 @@ VeryLongTypeName very_long_result = SomeValueWithAVeryLongName +
85
85
86
86
Operators are before the line break in these cases.
87
87
88
- ## Align function arguments vertically
88
+ ### Align function arguments vertically
89
89
90
90
``` c++
91
91
void FunctionWithAVeryLongName (int parameter_with_a_very_long_name,
@@ -101,7 +101,7 @@ void FunctionWithAReallyReallyReallyLongNameSeriouslyStopIt(
101
101
...);
102
102
```
103
103
104
- ## Initialization lists
104
+ ### Initialization lists
105
105
106
106
Long initialization lists are formatted like this:
107
107
@@ -115,7 +115,7 @@ HandleWrap::HandleWrap(Environment* env,
115
115
handle_ (handle) {
116
116
```
117
117
118
- ## CamelCase for methods, functions, and classes
118
+ ### CamelCase for methods, functions, and classes
119
119
120
120
Exceptions are simple getters/setters, which are named `property_name()` and
121
121
`set_property_name()`, respectively.
@@ -131,15 +131,15 @@ class FooBar {
131
131
};
132
132
```
133
133
134
- ## snake\_ case for local variables and parameters
134
+ ### snake\_ case for local variables and parameters
135
135
136
136
``` c++
137
137
int FunctionThatDoesSomething (const char* important_string) {
138
138
const char* pointer_into_string = important_string;
139
139
}
140
140
```
141
141
142
- ## snake\_case\_ for private class fields
142
+ ### snake\_case\_ for private class fields
143
143
144
144
```c++
145
145
class Foo {
@@ -148,7 +148,7 @@ class Foo {
148
148
};
149
149
```
150
150
151
- ## snake\_ case\_ for C-like structs
151
+ ### snake\_ case\_ for C-like structs
152
152
For plain C-like structs snake_case can be used.
153
153
154
154
``` c++
@@ -157,7 +157,7 @@ struct foo_bar {
157
157
}
158
158
```
159
159
160
- ## Space after `template`
160
+ ### Space after `template`
161
161
162
162
```c++
163
163
template <typename T>
@@ -167,16 +167,16 @@ class FancyContainer {
167
167
```
168
168
## Memory Management
169
169
170
- ## Memory allocation
170
+ ### Memory allocation
171
171
172
172
- ` Malloc() ` , ` Calloc() ` , etc. from ` util.h ` abort in Out-of-Memory situations
173
173
- ` UncheckedMalloc() ` , etc. return ` nullptr ` in OOM situations
174
174
175
- ## Use ` nullptr ` instead of ` NULL ` or ` 0 `
175
+ ### Use ` nullptr ` instead of ` NULL ` or ` 0 `
176
176
177
177
What it says in the title.
178
178
179
- ## Ownership and Smart Pointers
179
+ ### Ownership and Smart Pointers
180
180
181
181
"Smart" pointers are classes that act like pointers, e.g.
182
182
by overloading the ` * ` and ` -> ` operators. Some smart pointer types can be
@@ -202,14 +202,14 @@ Never use `std::auto_ptr`. Instead, use `std::unique_ptr`.
202
202
203
203
## Others
204
204
205
- ## Type casting
205
+ ### Type casting
206
206
207
207
- Always avoid C-style casts (`(type)value`)
208
208
- `dynamic_cast` does not work because RTTI is not enabled
209
209
- Use `static_cast` for casting whenever it works
210
210
- `reinterpret_cast` is okay if `static_cast` is not appropriate
211
211
212
- ## Do not include `*.h` if `*-inl.h` has already been included
212
+ ### Do not include `*.h` if `*-inl.h` has already been included
213
213
214
214
Do
215
215
@@ -224,7 +224,7 @@ instead of
224
224
#include " util-inl.h"
225
225
```
226
226
227
- ## Avoid throwing JavaScript errors in C++
227
+ ### Avoid throwing JavaScript errors in C++
228
228
229
229
When there is a need to throw errors from a C++ binding method, try to
230
230
return the data necessary for constructing the errors to JavaScript,
@@ -278,7 +278,7 @@ exports.foo = function(str) {
278
278
};
279
279
```
280
280
281
- ### Avoid throwing JavaScript errors in nested C++ methods
281
+ #### Avoid throwing JavaScript errors in nested C++ methods
282
282
283
283
When you have to throw the errors from C++, try to do it at the top level and
284
284
not inside of nested calls.
0 commit comments