CodingRules » History » Version 6
Jules Waldhart, 2016-05-31 13:45
about enum at google
1 | 1 | Jules Waldhart | h1. Coding Rules |
---|---|---|---|
2 | |||
3 | 4 | Jules Waldhart | *Table of Contents* |
4 | |||
5 | {{toc}} |
||
6 | |||
7 | 1 | Jules Waldhart | An unordered list of stuff we would like devs to follow |
8 | |||
9 | 4 | Jules Waldhart | h2. Naming |
10 | 1 | Jules Waldhart | |
11 | 4 | Jules Waldhart | h3. Classes, attributes, variables |
12 | |||
13 | 3 | Jules Waldhart | * ClassesAreCamelCase with first letter capital, also are all types (typedef, enum, struct,...) |
14 | * methodsAreCamelCase with first letter lowercase |
||
15 | 6 | Jules Waldhart | * _privateAttributeStartWithUnderscore and is camelCase |
16 | 1 | Jules Waldhart | * localVariable or local_variable, first letter lowercase |
17 | * avoid calling @a=function(1.0,6,false,true)@, declare local variables with descriptive name for the parameters: @a=function(step_size,iteration_nb,enable_XYZ,multi_thread)@ |
||
18 | |||
19 | 4 | Jules Waldhart | h3. Enums |
20 | |||
21 | 5 | Jules Waldhart | Put enums in an existing namespace or class, and/or *create a struct and put it inside*. |
22 | That struct can also contain methods to convert to/from string and other types. |
||
23 | Enums and their container struct are CapitalCamelCase, as their values (see example). |
||
24 | 1 | Jules Waldhart | |
25 | 6 | Jules Waldhart | Google coding style recommends using @MACRO_STYLE@ for enum values, or constant style, ie. starting with a "@k@": @kRobot@. It can be accepted, stay consistent within a "module"/class of move3d. |
26 | |||
27 | 1 | Jules Waldhart | <pre> |
28 | 4 | Jules Waldhart | struct RobotType{ |
29 | 5 | Jules Waldhart | enum Value {Robot, Human, Object, NotDefined}; |
30 | 4 | Jules Waldhart | std::string toString(Value v); |
31 | ... |
||
32 | } |
||
33 | 1 | Jules Waldhart | </pre> |
34 | 6 | Jules Waldhart | |
35 | |||
36 | 4 | Jules Waldhart | |
37 | h2. Unimplemented stuff |
||
38 | 3 | Jules Waldhart | |
39 | 2 | Jules Waldhart | * not implemented functions: put an @assert(false);@ in it, it will abort in debug mode, and do nothing in release. (instead of a print or whatever, which is totally unclear) |
40 | 1 | Jules Waldhart | * but mainly, avoid to commit unimplemented functions. |