Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Right now I am using Google C++ Style Guide in my C++ code and I was pretty happy with it.

Recently I was told that this guide is very bad: it is used internally by Google (I knew that), is outdated, and promotes some very bad practices. So I want to use another coding style.

What good and fairly used C++ style guides are there? I write code for both gcc and Visual Studio, and I use a lot of the C++11 features.

What I liked very much about Google C++ Style Guide was the indentation, the whitespace and the naming conventions (specially naming all classes, types - including typedefs, type aliases and template aliases - with capital first letter).

I know any answer is subjective (I hope this is ok on this site) and I would appreciate any opinion, but I am interested which guides are used these days.

share|improve this question
1  
You can always use what ever style you like, and then reformat it to the preferred style when you have to share it. Here is a style formatter that automates this astyle.sourceforge.net –  Mathew Foscarini Jan 7 at 0:23
3  
This question does have potential for opinion based answers. Rather than closing it for this reason, I would encourage answerers to focus on facts, such as known uses, recommendations by authorities, comparative studies and the like. –  andy256 Jan 7 at 0:23
    
@andy256 Couldn't have said it better myself. –  bolov Jan 7 at 0:28
4  
Who told you Google's style was bad, and why does their opinion matter to you? –  Mathew Foscarini Jan 7 at 0:39
    
@MathewFoscarini there was a reasonably recent discussion here, even though it wasn't too in-depth: chat.stackoverflow.com/rooms/10/conversation/… (but then, going through it in-depth is like going through the FQA) –  Cubbi Jan 7 at 4:47

3 Answers 3

up vote 10 down vote accepted

You can use the guideline from this book for general usage:

http://www.amazon.com/Coding-Standards-Rules-Guidelines-Practices/dp/0321113586

from Herb Sutter and Andrei Alexandrescu. It does not take into account C++11 though, but I think there will be a new edition.

But it will not answer about number of space instead of tabs or what kind of esoteric notation you want to enforce. But these are not the most important thing, most of the time just to have some consistency is the key.

share|improve this answer

As @user113896 earlier wrote, Bjarne Strostrup gave us a lot of style guidance. One of his fine achievements is JSF-C++ Coding style book. Beware, it's not for regular c++, more for embedded use, but it shows how things should be done to be clear and functional. Of course - You don't have to take everything into account - its a guide, not an order-book :).

share|improve this answer

If you haven't read Bjarne Stroustrup's Programming and Principles I strongly recommend you to read it because you can learn a lot from the language's creator. I have watched and read a lot from the C++ author and I can say that he has this fixation for style and is always telling people to write good, beautiful code that according to him is easier to debug and read. I believe that he is the greatest tutor and the best guide to writing stylish and beautiful C++ code.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.