Coding Style in ParaEngine

coding conventions used in C++, NPL, C# projects in ParaEngine. Edited by LiXizhi

References

Naming Convention

The first task you encounter when you start to write code is how to name your variables, objects, and functions. The importance of naming conventions can not be underestimated. Providing proper naming will result in self-documenting code, easily comprehended by others. Unless you want to obfuscate the source code, you should follow these guidelines.

Use a name that unambiguously describes a variable or object. A function should contain in its name a verb of the action that it implements.

Windows style (MFC applications, prepend Hungarian prefixes to identify the variable type): %CODE{"cpp"}% INT nSomeVariable; FLOAT fBarWeight; DWORD dwUsersNumber; BOOL bIsEngineStarted; DOUBLE dCircleArea; DOUBLE m_dCircleArea; //class private variable, prepend m_ prefix

PVOID pSomeVoidPointer;

const INT USERS_NUMBER;

int i, j, n, m, tmp; //some local loops variables, temporary variables

namespace MyNameSpace;

vector nUsers; vector pszUserNames;

class CSomeClass;

INT DoWork(INT nTimeOfDay); FLOAT CalculateRadius(const& Circle rCircle); INT StartIOManager(); INT OpenDvdPlayer(); //if abbreviation takes more than // 2 letters do not capitalize the whole word

%ENDCODE%

.NET platform (Hungarian notation, and prefixes are obsolete):

%CODE{"cpp"}% int someVariable; float barWeight; unsigned int usersNumber; bool isEngineStarted; double circleArea; double circleArea; //refer to a class private variable // in code as this->circleArea

void^ someVoidPointer;

const int UsersNumber;

int i, j, n, m, tmp; //some local loops variables, temporary variables

namespace MyNameSpace;

array users; array userNames;

class SomeClass;

int DoWork(int timeOfDay); float CalculateRadius(const& Circle circle); int StartIOManager(); int OpenDvdPlayer(); //if abbreviation takes more than 2 letters // do not capitalize the whole word %ENDCODE%

Spaces, Braces, and Parenthesis

%CODE{"cpp"}% void some_function(int param) { //function body }

class SomeClass { //class body };

// this is preferred by LiXizhi, because it is more clear about scoping. And code does not appear too clouded if (some_condition) { //... }

// this is preferred by K&R, because it is shorter. If you use this, use it consistently. if (some_condition) { //... } %ENDCODE%

The spaces in math expressions should follow this style:

%CODE{"cpp"}%

float a, b, c, d; int e, f, g, h;

a = (b + d) / (c * d);

e = f - ((g & h) >> 10); //good e =f-( (g&h ) >>10); //bad %ENDCODE%

Topic revision: r2 - 2009-06-14 - LiXizhi
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback