The unofficial coding best practise and code formatting conventions for XBMC
#1
Information 
There are some development notes and developing guidelines in the wiki like;
...but all those does not go down to the code level with info on the preferred;
  • Coding guidelines
  • Commenting guidelines
  • Include guidelines
  • Filename guidelines
  • Review guidelines

So lets discuss that here in this thread:

If there is a firmly established guideline in place, it will help the coding by multiple developers to go much smoother. Also, all developers (coders in particular) should be subscribed to the SVN mailing list and there should be a policy of encouraging review of the code by each other (with reference to the coding guidelines as needed).

The current code in places is a bit messy as far as layout goes, so here's an attempt at getting a format that we can all pseudo agree on to help us keep things readable. i've taken most of this from the scummvm code conventions, and altered it with my personal preferences (well, i did have to format all this :p )

XBMC Code Formatting Conventions

1. use common sense

these are conventions which we try to follow when writing code for xboxmediacenter. they are this way mainly for reasons of taste, however, sticking to a common set of formatting rules also makes it slightly easier to read through our sources. if you want to submit patches, please try to follow these rules.

as such we don't follow these rules slavishly, in certain cases it is ok (and in fact favorable) to stray from them.

2. braces

braces in your code should look like the following example:
Quote:if (int i = 0; i < t; i++)
{
[...]
}
else
{
[...]
}

class dummy()
{
[...]
}

3. indents, at two spaces, using spaces.
in msdev, the settings should be setup as follows:
Image

4. whitespace

1. conventional operators surrounded by a space character
Quote:a = (b + c) * d;

2. c++ reserved words separated from opening parentheses by a white space

Quote:while (true)


3. commas followed by a white space

Quote:somefunction(a, b, c);
int d, e;


4. semicolons followed by a space character, if there is more on line

Quote:for (int a = 0; b++; c < d)
dosomething(e); dosomething(f); // this is probably bad style anyway


5. when declaring class inheritance and in a ? construct, colons should be surrounded by white space

Quote:class buswheel : public rubberinflatable
(isnight) ? colormedark() : colormebright();


5. switch / case constructs

Code:
switch (cmd)
{
case ksavecmd:
  save();
  break;
case kloadcmd:
case kplaycmd:
  close();
  break;
default:
  dialog::handlecommand(sender, cmd, data);
}

6. naming

1. constants - use caps with underscore spacing where necessary.
Quote:const int SOME_KLUDGY_CONSTANT_NAME = 1;

2. variables - only rule is that they are obviously named. hovering in msdevstudio reveals the type, so type prefixing is optional.

3. member variables. prefix with m_
Quote:int m_myinteger

4. global variables. prefix with g_

please post your opinions on this, and i'll update as a consensus is reached.

cheers,
jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply


Messages In This Thread
The unofficial coding best practise and code formatting conventions for XBMC - by jmarshall - 2004-08-18, 17:44
[No subject] - by darkie - 2004-08-18, 19:22
[No subject] - by Butcher - 2004-08-19, 02:01
[No subject] - by ezar2003 - 2004-08-19, 03:05
[No subject] - by chadoe - 2004-08-19, 11:45
[No subject] - by Butcher - 2004-08-19, 12:42
[No subject] - by Nickman - 2004-08-19, 13:20
[No subject] - by jmarshall - 2004-08-19, 13:24
[No subject] - by Butcher - 2004-08-19, 13:48
[No subject] - by Butcher - 2004-08-19, 13:56
[No subject] - by chadoe - 2004-08-19, 18:44
[No subject] - by Nickman - 2004-08-19, 19:51
[No subject] - by Nickman - 2004-08-19, 19:51
[No subject] - by Bobbin007 - 2004-08-19, 20:59
[No subject] - by jmarshall - 2004-08-19, 21:21
[No subject] - by Bobbin007 - 2004-08-19, 23:34
[No subject] - by Gamester17 - 2004-08-23, 12:35
[No subject] - by Gamester17 - 2004-09-06, 11:30
[No subject] - by yuvalt - 2004-09-06, 17:05
[No subject] - by pade - 2004-11-04, 23:53
[No subject] - by Gamester17 - 2004-11-08, 13:23
[No subject] - by stcogoli - 2004-11-11, 20:33
[No subject] - by Gamester17 - 2005-01-24, 16:08
[No subject] - by Gamester17 - 2005-04-27, 13:05
a few additional suggestions - by deadken - 2005-05-17, 04:44
[No subject] - by dteirney - 2009-06-01, 11:33
[No subject] - by jmarshall - 2009-06-01, 11:42
[No subject] - by gsnerf - 2009-11-24, 15:07
[No subject] - by spiff - 2009-11-24, 15:16
Logout Mark Read Team Forum Stats Members Help
The unofficial coding best practise and code formatting conventions for XBMC0