Coding Conventions
From NetRace
Coding Guidelines
At the top of every .cpp file, before all other #includes (even standard includes), add this line:
#include "Sys.h"
Asserts should be used like:
ASSERT( false );
Asserts will stop in the debugger, and try to log a callstack. Assert's are commented out in Release and Profile builds.
Logging should be used like:
Log( "Frame: %d", frame );
It's currently configured to output to the debugger window. It's trivial to change it to output to a file (soon), stdout, a separate window (not implemented).
Logging is turned on for all builds. Can be turned off with a compiler switch.
Avoid built-in types int, float, double, etc. Instead use the types found in Sys.h. These include int16, int32, float32, float64.
Use SAFE_DELETE(), SAFE_DELETE_ARRAY() to delete objects created with new and new []. Use SAFE_RELEASE() to release COM objects.
Try to use internal wrapped functions for all operations. ie, don't use strcmp(), use StrCmp()... done use strcpy(), use StrCpy()... Don't call sin(), call Math::Sin(). If you can't find the internal equivalent for what you want to do, ask Ed.
Many headers are already included in Sys.h. For example, StrUtil.h, MathLib.h, as well as all of the STL headers.
We will be trying to transition over to Unicode only. This will be hard to get used to, but beneficial in the long run. Try to avoid strings, and use wstrings. wchar_t instead of char. Will try to add complete support to all the relevant libraries (Sys.h, StrUtil.h, etc) soon.
Style Guidelines
All code should be 3 spaces for tabs (spaces, not tabs!)
This example should show all you need to know for style. Please follow:
.h
//-----------------------------------------------------------------------------
// FILE: Test.h
//-----------------------------------------------------------------------------
#ifndef TEST_H
#define TEST_H
class Test
{
protected:
string m_testString;
int32 m_testInt;
public:
Test() { TestFunc1(); }
virtual ~Test() {}
virtual void TestFunc1();
private:
virtual int32 TestFunc2( int32 testVar1, float32 testVar2 );
};
#endif // TEST_H
.cpp
//-----------------------------------------------------------------------------
// FILE: Test.cpp
//-----------------------------------------------------------------------------
#include "Sys.h"
#include <windows.h>
#include "Test.h"
void Test::TestFunc1()
{
int testFuncVar;
testFuncVar = rand() % 2;
Log( "Hello World\n" );
}
int32 Test::TestFunc2( int32 testVar1, float32 testVar2 )
{
m_testInt = testVar1;
return (int32)testVar2;
}
