Project

General

Profile

CodeStyle » History » Revision 4

Revision 3 (Alex Afanasyev, 01/26/2014 11:20 AM) → Revision 4/30 (Junxiao Shi, 01/26/2014 08:23 PM)

# NFD code style guidelines 

 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: 

 * (amended 10). Global variables should have `g_` prefix 
 * (amended 11). **All** class variables should have `m_` prefix.    Static class variables should have `s_` prefix. 
 * (amended 33). We will use only `.cpp` and `.hpp` extensions 
 * (amended 35). File content should be kept within 80 columns. OK if some occasionally some lines exceed this limit. 
 * (amended 44). Avoid C-style casts.    Use `static_cast`, `dynamic_cast`, `reinterpret_cast`, `const_cast` where appropriate instead. 
 * (new).    Exceptions can be used in the code, but should be used only in **exceptional** cases and not in the primary processing path. 
 * (new).    When declaring/defining function/method, the return type should be put on a separate line before function/method name. 
 * (amended 68).    All three presented styles ARE acceptable.    First and third thirds ARE recommended (these are actually GNU styles). 
 * (amended 69).    The class declarations should have the following form: 

         class SomeClass : public BaseClass  
         {  
         public:  
           ... <public methods> metods> ... 
         protected:  
           ... <protected methods> method> ... 
         private:  
           ... <private methods> ... 
        
         public:  
           ... <public data> ... 
         protected:  
           ... <protected data> ... 
         private:  
           ... <private data> ... 
         }; 

     

 ``public``, ``protected``, ``private`` may be repeated several times without interleaving (e.g. (e.g., public, public, public, private, private) if this allows better readability of the code. 

 * (amended 70) Method and function definitions should have the following form: 

         void 
         someMethod()  
         {  
           ...  
         }