views:

158

answers:

3

I'm learning C++. For me, my programming style is just what looks the best; it doesn't seem to follow the rules of any one particular style. Here's an example

void f(int x){ //no space between close-paren and bracket
    if (!x){
        cout << "x is non-zero\n";
    } //closing bracket indented to the same level as the original statement
}

It's only slightly different for something like a class or a namespace:

class myClass {}; //space between class name and bracket, otherwise the same as functions

K&R style does uses that kind of bracketing for statements, but my style uses it for everything. I'd like to know if there's a name for it so I can say simply what my indent style is without having to explain using examples like these.

+1  A: 

Looks BSD KNF style. see http://en.wikipedia.org/wiki/Indent_style

(note, it's also the same style I prefer :) )

Earlz
That is pretty much exactly right, though I prefer to have a consecutive statement on a new line instead of following the closing bracket.
Maulrus
Well there is no one coding standard. Almost every project has a few tweaks added on to a major code style.
Earlz
A: 

It looks like a slight modification of K&R style; I'm not aware of any name for it. The potential variations on programming styles for a non-whitespace-sensitive language are so vast that you have to expect that few of them will have proper names.

Dan Story
I understand that, but if there's a chance of it being named I'd like to know so I can refer to it more easily in the future.
Maulrus
+4  A: 

I've never seen any code formatting guideline that recommends not including a space between ) and { and to my eyes it looks very ugly.

Let's call it Maulrus style.

Mark Byers
Yeah, the lack of a space doesn't look so good in this font; however, I'm willing to keep using it if I can finally get something named after me ;)
Maulrus