CodeStyle » History » Version 4
Junxiao Shi, 01/26/2014 08:23 PM
| 1 | 1 | Junxiao Shi | # NFD code style guidelines |
|---|---|---|---|
| 2 | |||
| 3 | NFD adopts [NDN Platform C++, C, C#, Java and JavaScript Code Guidelines](http://named-data.net/codebase/platform/documentation/ndn-platform-development-guidelines/cpp-code-guidelines/), with the following exceptions: |
||
| 4 | |||
| 5 | * (amended 10). Global variables should have `g_` prefix |
||
| 6 | * (amended 11). **All** class variables should have `m_` prefix. Static class variables should have `s_` prefix. |
||
| 7 | * (amended 33). We will use only `.cpp` and `.hpp` extensions |
||
| 8 | 3 | Alex Afanasyev | * (amended 35). File content should be kept within 80 columns. OK if some occasionally some lines exceed this limit. |
| 9 | 1 | Junxiao Shi | * (amended 44). Avoid C-style casts. Use `static_cast`, `dynamic_cast`, `reinterpret_cast`, `const_cast` where appropriate instead. |
| 10 | * (new). Exceptions can be used in the code, but should be used only in **exceptional** cases and not in the primary processing path. |
||
| 11 | * (new). When declaring/defining function/method, the return type should be put on a separate line before function/method name. |
||
| 12 | 4 | Junxiao Shi | * (amended 68). All three presented styles ARE acceptable. First and third ARE recommended (these are actually GNU styles). |
| 13 | 3 | Alex Afanasyev | * (amended 69). The class declarations should have the following form: |
| 14 | |||
| 15 | class SomeClass : public BaseClass |
||
| 16 | { |
||
| 17 | public: |
||
| 18 | 4 | Junxiao Shi | ... <public methods> ... |
| 19 | 3 | Alex Afanasyev | protected: |
| 20 | 4 | Junxiao Shi | ... <protected methods> ... |
| 21 | 3 | Alex Afanasyev | private: |
| 22 | ... <private methods> ... |
||
| 23 | |||
| 24 | public: |
||
| 25 | ... <public data> ... |
||
| 26 | protected: |
||
| 27 | ... <protected data> ... |
||
| 28 | private: |
||
| 29 | ... <private data> ... |
||
| 30 | }; |
||
| 31 | |||
| 32 | 4 | Junxiao Shi | ``public``, ``protected``, ``private`` may be repeated several times without interleaving (e.g. public, public, public, private, private) if this allows better readability of the code. |
| 33 | 3 | Alex Afanasyev | |
| 34 | * (amended 70) Method and function definitions should have the following form: |
||
| 35 | |||
| 36 | void |
||
| 37 | someMethod() |
||
| 38 | { |
||
| 39 | ... |
||
| 40 | } |