Functions or methods names: verb or adjectives: GetX, DoDispose, ClearArray, etc.
Predicated name for methods/functions with single return value: use Is, Has, or bool e.g., IsBroadcast();
Indentation: two space (not tab)
After , , :, and ; - put one space
Method return type: in column one
Method name: in column one
Variable name: e.g., CamelBlack - camelBlack UserName - userName
Function, property, event, or class name: CamelBlack (try to use descriptive names for classes and functions)
global variables - prefixed with a g_
global member function - prefixed with a m_
enume variables - suffixed with _e
defined types - optionally end with _t
define constant (static const class members, or enume constants) - all upper case letters
// declaring my-class.h
typedef struct {
uint32_t m_magicNumber;
uint32_t m_versionMajor;
} PcapFileHeader_t; // the trailing _t is optional
const uint8_t PORT_NUMBER = 17;
class MyClass
{
void MyMethod (int aVar);
int m_aVar;
static int m_anotherVar;
};
// implementing the my-class.cc
typedef struct {
uint32_t m_magicNumber;
uint32_t m_versionMajor;
} PcapFileHeader_t; // the trailing _t is optional
const uint8_t PORT_NUMBER = 17;
class MyClass
{
void MyMethod (int aVar);
int m_aVar;
static int m_anotherVar;
};
Portable integer types - uint8_t, int32_t, etc., instead of unsigned int/long;
One could use nested namespaces instead of ns3 namespace:
namespace ns3 {
namespace olsr {
...
} // namespace olsr
} // namespace ns3
namespace ns3 and namespace std shouldn't be used in the source code inside src/. and could be used in examples/, samples/, test/