JsonRpc-Cpp coding style ========================= I) Code layout The software uses the ANSI coding standard layout. Use 2 space indentation instead of tabs. void foo(int barc, char** barv) { int test = 0; if(test) { /* do something */ } else { /* do other thing */ } while(run) { /* do loop */ } for(i = 0 ; i < 2 ; i++) { /* do other loop */ } do { /* do another loop */ } while(run); } The C++ comments ('//') can be used as well as the C comments ('/* */'). /* my short comment */ // another short comment /* a longer comment * on multiple lines * ... */ II) Code organization The code has to follow these recommandations: - Always initialize your variables; - Put "static" keyword when functions / global variables is not used outside the file; - Try to avoid static variables in functions (try to make reentrant things); - All member variables of a class must be prefixed with "m_"; - Each global variable must be prefixed with "g_"; - Put an empty line at the end of each file. Each file, function, structure, classe and global variable MUST be documented using doxygen. Here is a complete example: /** * \file my_file.h * \brief Short description. * \author name * \date 2008 */ #ifndef MY_FILE_H #define MY_FILE_H /** * \struct my_struct * \brief Short description. */ struct my_struct { int a; /**< description of a */ char b; /**< description of b */ }; /** * \class MyClass * \brief Short description of MyClass. */ class MyClass { public: /** * \brief Constructor. */ MyClass(); /** * \brief Destructor. */ ~MyClass(); /** * \brief A function * \param count parameter description * \return true if success, false otherwise */ bool AFunction(unsigned int count); private: /** * \brief Member description. */ unsigned int m_count; }; /** * \var g_my_var * \brief Description of this global variable. */ struct my_struct* g_my_var = NULL; /** * \brief Doing something * \param a number to use * \param b char to use * \return 0 if success, -1 otherwise */ int foo(int a, char b); #endif /* MY_FILE_H */ III) Standards --------------- In order to compile and run on many operating systems the code has to be portable. Thus it is strongly recommended to write code which respect C++98 and POSIX standards.