Skip to content

Commit bc6eb10

Browse files
committed
CodingStyle: final decisions?
- _d suffix for naked struct/class types (not _t!) - m_ prefix for class members - prefer braces for single line ifs. Signed-off-by: Sage Weil <[email protected]>
1 parent f29b9bd commit bc6eb10

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

CodingStyle

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,31 @@ by section.
2828

2929
Google uses CamelCaps for all type names. We use two naming schemes:
3030

31-
- for structs (simple data containers), lower case with _t suffix:
32-
struct my_type_t {
31+
- for naked structs (simple data containers), lower case with _d
32+
suffix ('d' for data). Not _t, because that means typdef.
33+
34+
struct my_type_d {
3335
int a, b;
34-
my_type_t() : a(0), b(0) {}
36+
my_type_d() : a(0), b(0) {}
3537
};
36-
- for regular classes, CamelCaps, private: section, etc.
38+
39+
- for full-blown classes, CamelCaps, private: section, accessors,
40+
probably not copyable, etc.
3741

3842
* Naming > Variable Names:
3943

40-
Google uses _ suffix for class members. We haven't up until now. Should we?
44+
Google uses _ suffix for class members. That's ugly. We'll use
45+
a m_ prefix, like so:
4146

47+
class Foo {
48+
public:
49+
int get_foo() const { return m_foo; }
50+
void set_foo(int foo) { m_foo = foo; }
51+
52+
private:
53+
int m_foo;
54+
};
55+
4256
* Naming > Constant Names:
4357

4458
Google uses kSomeThing for constants. We prefer SOME_THING.
@@ -69,7 +83,11 @@ the code origin isn't reflected by the git history.
6983
- Always use newline following if:
7084

7185
if (foo)
72-
bar; // okay
86+
bar; // okay, but discouraged...
87+
88+
if (foo) {
89+
bar; // this is better!
90+
}
7391

7492
if (foo) bar; // no, usually harder to parse visually
7593

0 commit comments

Comments
 (0)