---++ Coding Style in !ParaEngine coding conventions used in C++, NPL, C# projects in ParaEngine. Edited by LiXizhi %TOC% *References* * %T% Lua Coding Style: http://lua-users.org/wiki/LuaStyleGuide * http://www.cse.iitk.ac.in/users/dsrkg/cs245/html/Guide.htm * http://www.codeproject.com/KB/cpp/cppstyle.aspx ---+++ 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 [[http://www.cse.iitk.ac.in/users/dsrkg/cs245/html/Guide.htm][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<int> nUsers; vector<char *> 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 ([[http://www.cse.iitk.ac.in/users/dsrkg/cs245/html/Guide.htm][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<int> users; array<String> 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%
E
dit
|
A
ttach
|
P
rint version
|
H
istory
: r2
<
r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r2 - 2009-06-14
-
LiXizhi
Home
Site map
CCWeb web
HaqiTeen web
Main web
ParaEngine web
TWiki web
Main Web
Users
Groups
Index
Search
Changes
Notifications
RSS Feed
Statistics
导航页WebTopMenu
Preferences
开发指南
Getting Started
ParacraftSDK
NPL
MCML
NPL Reference Manual
美术Mod
Account
Log In
English
简体中文
簡體中文
E
dit
A
ttach
Copyright © 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