Tremulous Forum

Mods => Modding Center => Topic started by: /dev/humancontroller on July 12, 2007, 06:14:14 am

Title: What indentation style do you prefer?
Post by: /dev/humancontroller on July 12, 2007, 06:14:14 am
I mean, of course, for the majority of the code, because slight mixing can be acceptable/good.
I ask this, because the stock version has one style in one file, and another style in another file. And I hate one of them, which I won't tell. Let's see...

I you have explanations, go ahead and write.
Title: What indentation style do you prefer?
Post by: David on July 12, 2007, 11:59:09 am
4 spaces for me.
Although tabs are best, as they let each dev have it how they want.
Title: What indentation style do you prefer?
Post by: tehOen on July 12, 2007, 12:01:35 pm
indentation is for the losers I code everything in 1 line
Title: What indentation style do you prefer?
Post by: benmachine on July 12, 2007, 12:58:52 pm
I hate Tremulous code's spaces around EVERYTHING.
Spacing is mostly good, but when it's even sometimes inside [] it can seem excessive and just as confusing as no spacing at all.
Yeah, and I voted four spaces.
Title: What indentation style do you prefer?
Post by: Ingar on July 12, 2007, 04:21:09 pm
Indentation is for code beautifiers
http://astyle.sourceforge.net/

I use tabs myself.
Title: What indentation style do you prefer?
Post by: /dev/humancontroller on July 12, 2007, 05:12:36 pm
Quote from: "benmachine"
I hate Tremulous code's spaces around EVERYTHING.
Spacing is mostly good, but when it's even sometimes inside [] it can seem excessive and just as confusing as no spacing at all.
Yeah, and I voted four spaces.

What looks good for me:
thaip funkshun( war neim, thaip_t twu, ... )
asd[0], qwerty[1337]
anotherLong.struct[ referenceWith->everything ].inside // space in [] when something long is in it

do you even disagree with these?
Title: What indentation style do you prefer?
Post by: /dev/humancontroller on July 12, 2007, 05:14:06 pm
Quote from: "Ingar"
Indentation is for code beautifiers
http://astyle.sourceforge.net/

I use tabs myself.

Sample result code plz?
Title: What indentation style do you prefer?
Post by: Ingar on July 12, 2007, 05:55:04 pm
Quote from: "/dev/humancontroller"

Sample result code plz?


Before:
Code: [Select]
int main(int argc, char ** argv) {
int a;
if (cin >> a)
{
cout << a << endl;
if (cin >> a)
{
cout << a;
}
}
return  0;
}

Command:
Code: [Select]
astyle --style=linux example.cpp
After:
Code: [Select]
int main(int argc, char ** argv)
{
        int a;
        if (cin >> a) {
                cout << a << endl;
                if (cin >> a) {
                        cout << a;
                }
        }
        return  0;
}
Title: What indentation style do you prefer?
Post by: David on July 12, 2007, 05:56:46 pm
I hate people who put the opening { on the same line as what it opens.
The { and } should line up!
Title: What indentation style do you prefer?
Post by: tehOen on July 12, 2007, 06:40:37 pm
omg formatting doesnt matter as long as it is readable
it is just a convention
btw ansi FTW
Title: What indentation style do you prefer?
Post by: /dev/humancontroller on July 13, 2007, 12:51:22 pm
Quote from: "David"
I hate people who put the opening { on the same line as what it opens.
The { and } should line up!

Do you hate me more than my style? :D
I accept that style because the indentation shows that you're in a new block.

The compactness of the code is also a requirement. When we have to execute 1 conditional statement, like a return, here are the options:
Code: [Select]
if( some > condition ) {
return;
}
// Allows you to quickly add debug lines like Com_Printf( "ZOMGWUTDAFUK\n" );
// Remove the braces once the program has been tested.

if( some > condition )
return;
if( some > condition ) return;
// Uh... these two are kind of interchangable,
// chose the second one if compactness is the first priority.

if( some > condition )
{
return;
}
// Does this make it better?


OK, if more than 1 statement is inside, blocks are required.
Code: [Select]
if( right ) {
right[0] = -1*sr*sp*cy+-1*cr*-sy;
right[1] = -1*sr*sp*sy+-1*cr*cy;
right[2] = -1*sr*cp;
}
if( up )
{
up[0] = cr*sp*cy+-sr*-sy;
up[1] = cr*sp*sy+-sr*cy;
up[2] = cr*cp;
}
// Well, the second one is less compact, but more readable.
// Wether the first or the second block is better, I don't know.

// What about this? eeewww
if( forward ) {

forward[0] = cp*cy;
forward[1] = cp*sy;
forward[2] = -sp;
}
Title: What indentation style do you prefer?
Post by: Kaleo on July 13, 2007, 03:14:38 pm
2. Or 3 sometimes.
Code: [Select]
//Fuck this shit...
{
  printf "I am";
  printf " listening to";
  printf " ManOwaR!";
}
Title: What indentation style do you prefer?
Post by: Undeference on July 13, 2007, 08:03:14 pm
http://www.linuxhq.com/kernel/v1.3/53/Documentation/CodingStyle
Title: What indentation style do you prefer?
Post by: tehOen on July 13, 2007, 10:39:49 pm
Code: [Select]

if( up )
{
up[0] = cr * sp * cy + -sr * -sy;
up[1] = cr * sp * sy + -sr * cy;
up[2] = cr * cp;
}

now it is more readable (I would kill myself if I had to read your code)

and for kaleo
printf( "I am" " listening to" " umbrella by " "rihanna." );
Title: What indentation style do you prefer?
Post by: /dev/humancontroller on July 13, 2007, 10:53:52 pm
Quote from: "Undeference"
http://www.linuxhq.com/kernel/v1.3/53/Documentation/CodingStyle

Thx. You wouldn't happen to also know the source of the additional readability spaces, would you?
Code: [Select]
func( var qwerty );