1# CodeStyle 2 3Our CodeStyle based on [google code style](https://google.github.io/styleguide/cppguide.html) (you can get google config like this: `clang-format -dump-config -style=Google`). 4But we have some modifications: 5 61. Indent: spaces 4. Line length: 120. 72. Delete spaces before public/private/protected. 83. All constants in UPPERCASE. 94. Enums in uppercase 10 Example: 11 12 ```cpp 13 enum ShootingHand { LEFT, RIGHT }; 14 ``` 155. Unix/Linux line ending for all files. 166. Same parameter names in Method definitions and declarations. 177. No `k` prefix in constant names. 188. No one-line if-clauses: 19 ```cpp 20 if (x == kFoo) return new Foo(); 21 ``` 229. Do not use special naming for getters/setters (google allows this: 23 ```cpp 24 int count() and void set_count(int count)) 25 ``` 2610. Always explicitly mark fall through in switch … case. Google uses its own macro, we can agree on /* fallthrough */. 27 ```cpp 28 switch (x) { 29 case 41: // No annotation needed here. 30 case 43: 31 if (dont_be_picky) { 32 // Use this instead of or along with annotations in comments. 33 /* fallthrough */ 34 } else { 35 CloseButNoCigar(); 36 break; 37 } 38 case 42: 39 DoSomethingSpecial(); 40 /* fallthrough */ 41 default: 42 DoSomethingGeneric(); 43 break; 44 } 45 ``` 4611. When a return statement is unreachable, but the language syntax requires it, mark it with something like return nullptr; /* unreachable */, or define UNREACHABLE as assert(0 && "Unreachable") and insert it before such return 4712. Use standard notices in comments (e.g. TODO:, NB!, no FIXME: allowed). 4813. Use standard flowerbox comments at the top of headers and translation units (agree on the format). 49 Temporary you can use this: 50 ``` 51 /** 52 * Copyright (c) Huawei Technologies Co., Ltd. 2019-2021. All rights reserved. 53 */ 54 ``` 5514. switch and case on the same level 56 For example: 57 58 switch (ch) { 59 case ‘A’: 60 ... 61 } 6215. Always put { } even if the body is one line: 63 For example 64 ```cpp 65 if (foo) { 66 return 5; 67 } 68 ``` 6916. Use `maybe_unused` attribute for unused vars/arguments. 70 ```cpp 71 int foo3([[maybe_unused]] int bar) { 72 // ... 73 } 74 ``` 75 76We are using clang-format and clang-tidy to check code style. 77