Question

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.

Was it helpful?

Solution

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

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

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow