views:

558

answers:

9

The following have been proposed for an upcoming C++ project.

  • C++ Coding Standards, by Sutter and Alexandrescu
  • JSF Air Vehicle C++ coding standards
  • The Elements of C++ Style
  • Effective C++ 3rd Edition, by Scott Meyers

Are there other choices? Or is the list above what be should used on a C++ project?

Some related links

+2  A: 

Hmm, strange question. Just choose standard which most of the team members are familiar with. Make some kind of poll for your team. Not sure how SO can help here :)

aku
I think you just did help!
Scott Langham
+1  A: 

Try this one, it's the one that NASA's Goddard space flight centre uses.

http://software.gsfc.nasa.gov/AssetsApproved/PA2.4.1.3.pdf

TraumaPony
+4  A: 

I really think it does not matter which one you adopt, as long as everyone goes along with it. Sometimes that can be hard as it seems that some styles don't agree with peoples tases. I.e. it comes down to arguing about whether prefixing all member variable with m_ is pretty or not.

I have been using and modifying the Geosoft standards for a while, these are for C++. There are some other at the what-is-your-favorite-coding-guidelines-checklist thread

Harald Scheirich
Heck I *chose* to use m_, and **I** think it's ugly!
Simon Buchan
+1  A: 

I've written a coding standard for a major British company and was very conscious of putting reasons why I selected certain things rather than just make it a bunch of "Thou shalt" pronouncements. (-:

As a quick way out, I'd suggest mandating:

  • Scott Meyers's Effective C++ 3rd Edition (Amazon link) - if you can find a copy of the 1st edition of this book then buy it for the overview of OO design which was removed from later editions. )-:
  • Scott Meyer's book Effective STL (Amazon link) - you must use STL to use C++ efficiently.
  • Steve McConnell's book Code Complete 2 (Amazon link) - not C++ specific but full of great insights.
Rob Wells
+1  A: 

Coding standards are only meaningful if they help you write code. So they just need to keep your code consistent (ie if someone puts m_ and ther don't if can take longer to grok the code than if they all used the same style).

That's all they (should) do, so just pick up your exisitng code and make sure your team codes to the same style.

I like to think of it like cartoons. If you become a cartoonist on the Simpsons, you have to draw eyes in the official way or everything looks pants, but if you go to Family Guy, you have to draw them differently. Neither way is wrong.

Too many standards are about meaningless restictions, written by people who don't code themselves (or consider themselves too good to keep to them). Others try to teach you how to code. Neither has its place in a good standard, those just make it easier for you to look at some code and understand what its doing.

eg. my standards include rules for naming directories - you will always have your code in a directory called the same name as the project, and all binaries go in the bin subdir, with all config files in the same place, and a changelog, etc. All simple stuff, but I guarantee I'll never find a project called something different with its binaries in the root directory where I don't know what changes were made to it. Simple, easy stuff that makes a huge difference.

gbjbaanb
+3  A: 

C++ Coding Standards: 101 Rules, Guidelines, and Best Practices (C++ In-Depth Series) by Herb Sutter and, Andrei Alexandrescu.

Scott Langham
Very good book to create your own coding standard, because each company is different, and they are chances your company is not google nor NASA.
Nikko
+1  A: 

I agree with Harald Scheirich, it is most important to have the team agree on what the rules should be rather than just picking a set that has been recommended by outsiders.

My personal recommendation would be to read Code Complete, 2nd Edition by Steve McConnell which describes (among a whole lot of other useful stuff) several common coding standards and offers commentary on each. This might help your team in setting up your own standards.

TomiJ
A: 

Poco C++ Coding Style Guide.pdf

Comptrol