Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

closed as off-topic by amon, durron597, Ixrec, Snowman, Kilian Foth Oct 8 '15 at 11:35

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking us to recommend a tool, library or favorite off-site resource are off-topic for Programmers as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – amon, durron597, Ixrec, Snowman, Kilian Foth
If this question can be reworded to fit the rules in the help center, please edit the question.

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 – ThinkingMedia Jan 7 '14 at 0:23
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 '14 at 0:23
@andy256 Couldn't have said it better myself. – bolov Jan 7 '14 at 0:28
Who told you Google's style was bad, and why does their opinion matter to you? – ThinkingMedia Jan 7 '14 at 0:39
@MathewFoscarini there was a reasonably recent discussion here, even though it wasn't too in-depth:… (but then, going through it in-depth is like going through the FQA) – Cubbi Jan 7 '14 at 4:47
up vote 11 down vote accepted

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

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

The C++ Core Guidelines are a set of tried-and-true guidelines, rules, and best practices about coding in C++, you can find them here:

They are written by, among the others, Bjarne Stroustrup and Herb Sutter.

share|improve this answer

The criticisms of Google's C++ style guide (and I agree some are justified) are not about Google's naming conventions or indentation style but rather about some of their other rules and policies. Indentation / formatting and naming conventions are both something of a matter of taste and are fertile ground for endless programmer religious wars but in C++ where unlike say C# there is no universal standard the only really important guideline is consistency. For a new project, pick a naming convention and indentation style you like and use it consistently. For an existing project, stick with the convention already in use. Rule 0 in C++ Coding Standards is "Don't sweat the small stuff." where they argue that naming conventions and indentation style are just not that important as long as you're consistent.

A big productivity booster for me has been automating indentation / formatting using clang-format. Once you've settled on some indentation and formatting rules, I highly recommend setting up a customized .clang-format configuration file and then never having to worry about it again :-)

Clang-format is a standalone tool and doesn't require you to be using clang as a compiler. There's even an official plugin available for Visual Studio.

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

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