PDA

View Full Version : Your C++ Coding Preferences


naruto1327
07-18-2006, 11:52 PM
I would like to know some of your C++ Coding Preferences.
With:

- Indentation
-- Four Spaces
- Bracket placement

void shout()
{
cout << "HELLO!!!!!!!";
}

- Spaces between operators and declarations
-- Yes: n + m; Yes: int n = 1;
- Spaces between function name and starting parenthesis
-- None: shout();
- Spaces between loop name and starting parenthesis
-- One: if (n == 0)
- Where the * goes in declaring a pointer (next to the type name or the variable name)
-- Not sure for now, thats why I'm asking for your preferences but for now it's: int * n;
- Where the & goes in declaring a reference (next to the type name or the variable name)
-- Same as pointers: int & m = n;
- Whether you omit the <int> in the following specialization:
(
template <> void swap<int>(int &, int &)
)
-- Yes

Responses would be very helpful. :)

Beazel
07-19-2006, 12:49 AM
I don't know much about C/C++, but this applies to all types of coding I do.

Indentation: Tab.
Bracket Placement: For one-liners, I use int main() {, for anything more than one line:
int main()
{
std::cout << "lol, C++\n";
cin.get();
}
Spaces between operators and declarations: Yes.
Spaces between function name and starting parenthesis: No.
Spaces between loop name and starting parenthesis: Yes.
Spaces for references and pointers: No.
Whether you omit the <int> in the following specialization: No clue what that is. :D

naruto1327
07-19-2006, 01:38 AM
What about the int * n and int & n?

Thanks for replies!

TwitcH
07-19-2006, 02:52 AM
What about the int * n and int & n?

Thanks for replies!

I normally do:

int *n

And:

int &n

But im not a C++ coder, good old C for me ;)

Beazel
07-19-2006, 03:12 AM
What about the int * n and int & n?

Thanks for replies!

Spaces for references (&) and pointers (*): No.

;)

naruto1327
07-20-2006, 04:04 AM
So you do int&n and int&n, Beazel?

By the way, nice sig. ;)

Eriond
07-20-2006, 04:08 AM
int main()
{
cout << "Hello." << endl;
for (c = 0; c < 10; c++){// (Haha, get it? C? C++? Haha? Aww.. you're no fun.)
LoopStuff()
MoreLoopStuff()
}
}


And always, always int* n. Helps reminding me that I'm not actually dealing with an int ^_^

naruto1327
07-20-2006, 04:15 AM
So which way should I do it?

TwitcH
07-20-2006, 04:37 AM
Whichever way makes more sense to you. ;)

naruto1327
07-20-2006, 05:28 AM
I think I'll do it the way Eriond does it. ;)

n0madic0debc
07-21-2006, 05:03 PM
I think I'll do it the way Eriond does it. ;)
Yeah out of the ways the other guys said Eriond looks like you will remember what your dealing with.

naruto1327
07-21-2006, 10:06 PM
Should I alternate between the two when this happens?


#include <iostream>
using namespace std;
int main()
{
int i = 2;
int* n = i;
int *a, *b, *c;
cin.get();
return 0;
}