[ODE] Coding style in ODE
Remi Ricard
remi.ricard at simlog.com
Mon Apr 9 07:34:32 MST 2007
Hi,
I already sent messages to this list about creating a coding style for
ODE. I just want to tell everyone that I don't want to impose my style.
I don't care about the style to be used I just want to be able to set my
editor (emacs) to indent and present the file in a nice and standardized
manner.
Some people on the list talked about astyle (ref:
http://astyle.sourceforge.net/) I did some test and this application
looks really good. Since the code is available for windows, Linux and
OSX. Almost everyone could be able to use it.
I said earlier that I will try to create a standard for ODE by looking
at the code. I did my homework and created a configuration file for
astyle. (see below).
What I want to suggest is this.
Since I know that updating all the files at once will create some
problem when doing a "svn diff" to look at "real" code change since real
code change will be buried deep in cosmetic change.
I suggest to apply astyle only on part of code to be patched.
I will take longer to have all the code to follow the new "ODE style"
but this will decrease the code change pollution.
This is my method to create a patch following the new coding style
- Create a new repository (called sandbox_astyle)
- Make your change to this sandbox
- Apply astyle to the modified files
- Create a new repository (called sandbox_ode)
- Merge only the part that include bug fix or new code from
sandbox_atstyle to sandbox_ode.
- Create a patch with sandbox_ode.
- Submit patch to SourceForge.
You have below the options file needed by astyle and also small test
cases with the code in a strange format with code in a standardized format.
As I said earlier I'm open to discussion about what the new formatting
should be but if possible we should try to keep the formatting in a way
that can be generated/verified by astyle.
Remi
--------------------------
Test file below
/**
*****************************************************************************
* This file test the formating done by astyle
*
* ref: http://astyle.sourceforge.net/
*
* Copyright GPL
*
* @file ode_test_astyle.cpp
*
* @author Remi Ricard
*
* @par Created:
* 05 Apr 2007
*
* This should by saved and used as the astyle's options file
# astyle formatting options file -- start --
# ------------------------------------------
# set default parsing to: Kernighan&Ritchie style formatting/indenting.
# Break brackets from class and function declarations, but attach
brackets to pre-block command statements.
brackets=linux
# set 2 spaces per indent
# Ex:
# if (isFoo) {
# bar();
# }
indent=spaces=2
# indent switch blocks
indent-switches
# ################################################
# } else {
# becomes
# }
# else {
brackets=break-closing
# suffix of original files should be .pre
suffix=.orig
max-instatement-indent=40
# Insert space padding around parenthesis on the outside only
pad=paren-out
# Don't break complex statements and multiple statements residing on a
one-line=keep-statements
# Don't break one-line blocks.
one-line=keep-blocks
# astyle formatting options file -- end --
# ----------------------------------------
*
*
*************************************************************************///
//234567890123456789012345678901234567890123456789012345678901234567890123456789
// 1 2 3 4 5 6 7
//
============================================================================
// Test 1:
// Identation should be 2 character
// Should becomes
// int Fct2()
// {
// if (1)
// return;
// }
int Fct()
{
if (1)
return;
}
//
============================================================================
// Test 2:
// In a class statement Don't ident 'public:', 'protected:' and 'private:'
// Should becomes:
// class myClass1 {
// public:
// int myData1;
// };
class myClass {
public:
int myData1;
};
//
============================================================================
// Test 3:
// Break brackets from class and function declarations, but attach
// brackets to pre-block command statements.
// Should becomes:
// int Fct1()
// {
// if (1) {
// int b = 3;
// }
// }
int Fct() {
if (1)
{
int b = 3;
}
}
//
============================================================================
// Test 4:
// Break closing header (e.g. 'else', 'watch')
// Should becomes:
// int Fct1()
// {
// if (1) {
// return 3;
// }
// else {
// return 4;
// }
// }
int Fct1()
{
if (1)
{
return 3;
} else {
return 4;
}
}
//
============================================================================
// Test 4:
// Indent 'switch' block
// N.B. I found both in the different file but indentation was prevalent
// Should becomes:
// int Fct(int arg) {
// switch (arg) {
// case 0:
// arg +=1;
// break;
// case 1:
// {
// arg +=2;
// break;
// }
// }
// return arg;
// }
int Fct(int arg)
{
switch (arg)
{
case 0:
arg +=1;
break;
case 1:
{
arg +=2;
break;
}
}
return arg;
}
//
============================================================================
// Test 5:
// Don't indent 'case' block
// Should becomes:
// int Fct(int arg)
// {
// switch (arg)
// {
// case 0:
// arg +=1;
// break;
// case 1:
// {
// arg +=2;
// break;
// }
// }
// return arg;
// }
int Fct(int arg)
{
switch (arg)
{
case 0:
arg +=1;
break;
case 1:
{
arg +=2;
break;
}
}
return arg;
}
//
============================================================================
// Test 6:
// Don't add extra indentation to backet
// Should becomes:
// int Fct(int arg)
// {
// if (1) {
// return 1;
// }
//
// return 0;
// }
int Fct(int arg)
{
if (1) {
return 1;
}
return 0;
}
//
============================================================================
// Test 7:
// Indent a maximum of # spaces in a continuous statement, relative to
the previous line
// Should becomes:
// int fooArray[] = { red,
// green,
// blue };
//
// Function(aRealllllllllllllllllyLongggggggArggggggggNameeeeeeee1,
// aSecondReallllllllllllllyLongggggArggggggNameeeeeeee1);
// aSecondRealllllllllllllllllyLongggggggArggggggggNameeeeeeee1);
int fooArray[] = { red,
green,
blue };
Function(aRealllllllllllllllllyLongggggggArggggggggNameeeeeeee1,
aSecondRealllllllllllllllllyLongggggggArggggggggNameeeeeeee1);
//
============================================================================
// Test 8:
// Insert space padding around parenthesis on the outside only
// Should becomes:
// int Fct()
// {
// if (isFoo (a, b) )
// bar (a, b);
// }
int Fct()
{
if (isFoo(a, b))
bar(a, b);
}
//
============================================================================
// Test 9:
// Don't break complex statements and multiple statements residing on
// a single line.
// Should stay:
// int Fct()
// {
// int a = 3; cout<<a<<endl;
// if (a) a += 1; return a;
// }
int Fct()
{
int a = 3; cout<<a<<endl;
if (a) a += 1; return a;
}
//
============================================================================
// Test 9:
// Don't break one-line blocks.
// Should stay:
// void setGravity (dReal x, dReal y, dReal z)
// { dWorldSetGravity (_id,x,y,z); }
void setGravity (dReal x, dReal y, dReal z)
{ dWorldSetGravity (_id,x,y,z); }
More information about the ODE
mailing list