Existing Standard Style and Coding standard docume

2020-02-07 17:55发布

问题:


Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 4 years ago.

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

  • Do you think a software company should impose developers a coding-style?
  • https://stackoverflow.com/questions/66268/what-is-the-best-cc-coding-style-closed

回答1:

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



回答2:

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



回答3:

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 :)



回答4:

High Integrity C++ Coding Standard Manual - Version 2.4



回答5:

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



回答6:

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.


回答7:

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_ for variable members and someone doesn't, it 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 existing 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 restrictions, 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.



回答8:

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.



回答9:

Lockheed Martin's JSF Air Vehicle C++ Coding Standards is an interesting read but it's a bit overkill unless you're working in fields where a bug can kill people. It's still a very important example to look at from a computer ethics standpoint about an example of how to program with safety and correctness being top priority.

For general-purpose C++ coding, I'd personally recommend C++ Coding Standards by Herb Sutter. From the very beginning, it emphasizes what not to standardize (things relating to style or preference rather than practices that promote safety, correctness, efficiency). It's also among the easiest reads in your list giving very brief but concise arguments for each standard, making it something easy to show your co-workers.



回答10:

Poco C++ Coding Style Guide.pdf



回答11:

  • Apple Coding Guidelines for Cocoa

  • GNU Coding Standards

  • Bell Labs' Recommended C Style and Coding Standards

  • reserved names from POSIX / ISO

  • Facebook HHVM Coding Conventions

  • GeoSoft C++ Programming Style Guidelines

  • LLVM Coding Standards

  • C Style and Coding Standards for SunOS