Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
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
C++ Coding Standards: 101 Rules, Guidelines, and Best Practices (C++ In-Depth Series)
by Herb Sutter and, Andrei Alexandrescu.
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
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 :)
High Integrity C++ Coding Standard Manual - Version 2.4
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
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.
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.
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.
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.
Poco C++ Coding Style Guide.pdf
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
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
C++ has several types of styles: MFC, Boost, Google, etc. I would like to examine these styles and determine which one is best for my projects, but I want to read from the official style guidebook. Does anyone have an official guide that they typically use?
Here are two that I found. I bet there are more:
http://google-styleguide.googlecode.com/svn/trunk/cppguide.html
http://www.boost.org/development/requirements.html
Note: This is NOT a discussion about which style is best... only a call for official style guides that people currently use. Please refrain from bashing other style guides that you don't like.
Side question: Is there a good tool that can examine source code and tell if it matches a given style guide?
Not a Coding Guideline per se, but I find this mighty useful: Bjarne Stroustrup's C++ Style and Technique FAQ
There's no such thing as an "official" style guide - the C++ standard is entirely silent on style. One book on the subject by two highly knowledgable C++ guys is C++ Coding Standards by Sutter & Alexandrescu.
Other answers state that there is no official style guide, which was true at the time.
But in 2015, Bjarne Stroustrup announced the C++ Core Guidelines, an open source project to build authoritative guidelines for modern C++ code, led by Stroustrup himself and published by the Standard C++ Foundation:
http://github.com/isocpp/CppCoreGuidelines
In relevance to this question, the Core Guidelines also link to other guidelines, with added comments. About the often recommended Google C++ Style Guide, they say:
Geared toward C++03 and (also) older code bases. Google experts are now actively collaborating here on helping to improve these Guidelines, and hopefully to merge efforts so these can be a modern common set they could also recommend.
I have also written some tips for good coding in c++:
http://www.ivanism.com/Articles/CodingStandards.html
The post starts with:
The goal of coding standards are to increase the business value of the code. The most obvious (and indeed most important) way to do this is to make the code robust and low defect. Equally important, but more subtle goals include reducing coder friction and maintainability. As such, standards should be kept minimal -- simple enough to actually follow, and important enough to remember.
These standards should be used when building new source files. When an existing file needs to be changed, that is an appropriate time to bring it up to standard. However, it's never a good time to edit a file merely to bring it up to standard. If it ain't broke, don't "fix it" and remember to always "Keep it Working".
You'll notice that I don't touch on the classic "Religious" points:
tabs vs. spaces
indentation style
curly brace style
etc...
Consistency within a file is important and improves readability. But allowing coders to express themselves is also important. So, if you edit a file, either conform to the religion of that file, or convert the whole file to a new, consistent format. If you convert the whole file, you are effectively taking ownership of it, so be prepared to be the go-to person, or leave it as is.
C++ doesn't have and doesn't need an official style. Many organisations impose style guides on their contributors to try to maintain some kind of corporate look and feel; some of these contain snippets of good advice, but many just force you to add strange decorations that seemed like a good idea to someone writing a completely different language in the 1980s.
The only really useful advice you'll find amongst the waffle is:
Define a consistent way to distinguish types, objects, and some kinds of function (such as accessors and factories), so you'll know to write (for example) Thing thing = GetThing(); without looking the names up.
Don't start names with underscores. This is forbidden in some circumstances, and it's simpler and more readable to not do it at all than to worry about exactly when you can.
Spare a thought for the poor chap (perhaps you) who has to read and maintain the code in a few years' time.
Keep it simple.
Use your brain.
Another style guide are the The JSF air vehicle C++ coding standards.
I use my own style, which I have written up here. Whether or not you are interested in it as a style, if you're looking at styles in general you may find my discussion on the motivation for it to be useful.
To the side question: I don't personally know of any tools that analyze the style in use, but there are tools that reformat source to a given style guide. One that comes to mind is Artistic Style.
As for the side question, what you need is a static analysis tool. An expensive and huge tool is Klocwork. I've used it at a couple of shops and it can be set up to issue warnings against style issues. I don't recommend it for single users; it is more for a corporate environment. Although they may have stripped down versions for individuals.
Remember to Google for static analysis tools.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
what is the most advanced c or c++ book you ever read?
i am asking this because i already read lots and lots of books on c and c++ on a lot of topics including (object oriented programming-data structures and algorithms-network programming-parallel programming (MPI-PThreads-OpenMP-Cilk-Cuda)-boost library....). So whats next. I still want to advance.. especially in c.
Scott Meyers:
Effective C++
More Effective C++
Effective STL
Modern C++ Design
(For C) Expert C Programming: Deep C secrets without a doubt.
The C++ Standard. You cannot get any more advanced than this.
Similarly for C, there must be a book on the C99 standard, perhaps this page will help: http://careferencemanual.com/
Modern C++ Design by Andrei Alexandrescu.
Explains a few design patterns in detail, and explains how powerful C++ can be.
My favourite "difficult" C++ book is this Template Metaprogramming one: C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond.
It seems to me there aren't half as many books about C programming as there are about C++. The language just isn't that complex.
One interesting read might be P. J. Plauger The Standard C Library. It is supposed to contain some masterful code. It's on my to-read list.
The ubiquitous Stevens "Advanced Programming in the Unix Environment".
Depending on your definition of advanced, and whether you are focused on the languages themselves or topics is / using those languages (C / C++).
Numerical Recipes in C - not say this is good style usage, just advanced material
Algorithm Design Manual by Steven Skiena
Advanced Compiler Design and Implementation by Muchnick
Optimizing Compilers for Modern Architectures by Allen & Kennedy
Of course a Zen style answer would be to study non-C/C++ languages to learn more about C/C++. Smalltalk, Lisp, Scheme, Haskell, Python, Prolog, or Forth for example of languages from a different programming paradigm, which could expand your approach for development in general.
Alexander Stepanov and Paul McJones, "Elements of Programming".
Large Scale C++ Design by John Lakos.
Practical advice on managing the complexity of compiling/linking and executing large C++ programs. Talks a lot about decoupling and how to avoid the many kinds of dependencies that arise in C++.
(This is something most C#/Java developers, and sadly some C++-devs too, rarely understand.
IMO, it's a pain they need to. I wish we had modules in C++ already.)
The Design and Evolution of C++ by Bjarne.
It's nice to know the history of some features. Makes it much easier to understand why and how stuff works, and thus also easier to remember and explain to others why some things are the way they are.
I am not sure if you would consider these advanced, but I would surely put them in the category of must have references:
The C++ Programming Language Special Edition (3rd) by Bjarne Stroustrup
The C++ Standard Library: A Tutorial and Reference by Nicolai M. Josuttis
The other books I would recommend have already been listed by others.
You really want to test your mental limits? Then try these:
Alexandrescu: Modern C++ Design
Abrahams&Gurtovoy: C++ Template Metaprogramming
These books look deceiptively thin, but they stretch the limits of template programming, your C++ compiler, and your brain.
Hey nobody mentioned about Bruce Eckel's Thinking in C++ Volume 1 And Volume 2. When I read it as the first book it went straight way above my head. However as now I have good experience and have read books like Effective/Exceptional C++ so Eckel's book is now an ordinary stuff. However no doubt its a very popular book (4.5 stars on Amazon - 84 customer reviews).
Exceptional C++ by Herb Sutter.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm a practicing C++ programmer (on Unix and gcc 3.x) for the past 6-7 years. I've read Scott Meyer's Effective C++, More Effective C++ and Effective STL cover-to-cover and have lived and practiced his suggestions/techniques along with Boost. I would like to move on to the more advanced aspects of C++ - something along the lines of 'Modern C++ Design' by Andrei Alexandrescu. However, before starting to read this, I am wondering if I should spend time reading Herb Sutter's Exceptional C++ books as well. How would you compare the Effective C++ series with Sutter's books?
Thanks a lot in advance for your response.
Read as much as you can - differing perspectives are always valuable.
Yes, absolutely. Herb Sutter covers a lot of very important, but generally poorly understood areas of the language and provides lots of useful guidance for writing more robust code.
While it's true that much of the material originated on the gotw site, it is expanded and better organized in the books. If you can answer all of the problems correctly then you find that you are very rarely faced with code that you don't understand why it behaves like it does. You may also find yourself heading off many potential problems that you spot in code before they become real issues.
I got a lot more out of the Exceptional C++ books than I did out of Effective C++, but this is going to be a very personal thing.
Frankly, Herb Sutter yanks a lot in the exception safety ever since the introduction of the idea in one of the journals of the pre-2000 age. The fact he used it a lot on replication and transactional systems makes sense, and unless you are a huge follower and interested in only the software of such 'safety' kind you will be bored to death. Meyers is far more practical and engaging.
Besides, if you want to move on, there are other books in the series, notably from the legends and not the writers for the sake of writing. Look up the bits from Nicolai Josuttis (C++ Templates: The Complete Guide), Aleksey Gurtovoy (C++ Template Metaprogramming) and more recently 'Daddy 2' Stepanov. In my opinion, they are more influential, knowledgable, practical and shaping than anything DDJ or exception safety induced writeups...
And of course, if you ever need to go back to basics (and there is always a reason to), one of the best possible books on the subject is by the daddy himself: The C++ Programming Language (most underestimated and skimmed over book out there).
Read The Definitive C++ Book Guide and List. "Exceptional C++" is on the list.
I like the C++ Coding Standard book because it's just that, a coding standard.
Effective C++ introduces important ideas, and was my first read too. C++ Coding Standards however is shaped like a coding standard, which any person programming should have. There are a number of other coding standards available, Sutter's one has the advantage of being concise and well explained (only 100 items very neatly classified).
I would take the time, if I were you, to read the C++ Coding Standards and the Guru of the Week entries before moving on to meta-template programming.
Meta-template programming is interesting. I loved Modern C++ Programming and its approaches. However it is less used in practice I think, strengthen the basics as much as you can, then you can always play around with 'new' ideas.
I would absolutely recommend the Exceptional C++ books if you're looking to move into more advanced C++. My sense from reading both series is that the Effective C++ books tell you how to write code that doesn't completely suck, and the Exceptional C++ books tell you how to write code that's rock-solid and bulletproof. I was less taken with Modern C++ Design; if you want to get into serious template metaprogramming it's pretty much the definitive work, but I found it a little... out there for my taste, particularly where he builds this gloriously complicated template structure that'll bring tears to your eyes with its sheer beauty, and then mentions "Oh yeah, this doesn't actually work on any compiler that's currently available".
I found both books interesting and useful. There are lot of common topics and you might already know them, but certainly it will help.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm something of a new, reluctant convert to C++ from a Pascal, Ruby, and PHP background. I haven't worked with Pascal since a few months of torture with "Delphi Turbo;" since then I've practically been eating and sleeping Ruby and PHP. I'm already well acquainted with object oriented programming and many various subjects.
My main trouble is that I already know the rudiments of C/C++ programming, less the actual experience of working with C++. I worked with C for long enough to realize that even without macros, etc, I didn't want to work with it. (Some of the disgust was from maintaining a CGI application in C, when accustomed to Pascal's automatic string management.) I know just enough C++ to be dangerous to myself and anyone else unwitting enough to use my "code."
I'd really like to work up to a good enough understanding of C++ to use libraries like Crypto++ and Boost without major problems or in-depth knowledge of the language's intricacies. I just need to figure out how to work with C++ without killing myself (either with C++, or with the long-standing dislike that I'm already battling).
What are effective resources that will teach me C++ without assuming that I must be retaught all basic programming? I'd rather not relearn concepts that I already know, unless the paradigm in C++ is significantly different. I'm also learning on my own time, so don't recommend me a book complex enough to need a guru to explain to me, please! And I have an effective budget of $0 for learning C++, so please keep suggestions to quality online resources or books common enough that I could likely find them at the library.
Read Effective C++ by Scott Meyers - it's a good guide for getting past the basics of C++ and showing how to write and use "correct" C++ code
The C++ FAQ Lite is a great resource.
I highly recommend Stroustrup: The C++ Programming Language (Third Edition). As the author of C++ he is the authority on the language, and the book is useful as a reference as much as it is for learning the language. It's common enough that most good general purpose libraries will have a copy. He goes into quite some depth on all the features of C++, including explanations of why certain design decisions were made in the language. Personally, I think this is the best book around for programmers to learn C++.
Once you have a good grip on core C++, David Abrahams and Aleksey Gurtovoy's book, C++ Template Metaprogramming, goes into further depth and provides many examples of how C++'s template system allows you to perform complex compile-time programming, a highly valuable skill these days. This one is a little less common but you can probably find it at a university library.
I can give you a couple of keywords you might want to research in more detail:
RAII (Is pretty much the technique that ensures you don't have to worry about memory leaks. Very convenient)
Generic Programming (The STL in particular. Experiment with iterators and the standard library algorithms, and see just how powerful these abstractions are. They're a key part of what I like about C++)
Functors (Perhaps too simple on their own, but the way they can be used instead of function pointers with the algorithms mentioned above is interesting)
And just get familiar with templates, and "mild" forms of template metaprogramming. (Traits classes, for example, and (partial) specializations.
And just keep an eye on the C++ questions here on SO. A lot of interesting topics are regularly brought up.
But the best advice is probably to keep it completely separate from C. Forget everything you learned about how to use C. It either doesn't apply in C++, or leads to inferior code that is harder to read and maintain.
It's an interesting language in its own right, and has a number of unique features. Leverage those, and it can actually be fun to work with C++. Treat it as an overengineered Java, PHP or C, and it'll just make you want to throw up.
You need to write code. A lot of code in C++. There is no substitute. You also need to read good code.
I agree with the suggestion for Scott Meyers' books though. Those are pretty good.
Part of your learning will be the leap from procedural programming to OO.
I would highly recommend the book "C++ Common Knowledge" by Stephen C. Dewhurst. Don't know if it's common enough to be found at the library (it's not at mine, but my library sucks for computer books that aren't 5-10 years out of date), but it does an excellent job of taking the complex aspects of C++ and making them easy to understand, without dumbing anything down for beginners. Definitely worth the investment.
To quote from the back of the book:
This book is for you if
You're no "dummy," and you need to get quickly up to speed in intermediate to advanced C++
You've had some experience in C++ programming, but reading intermediate and advanced C++ books is slow-going
You've had an introductory C++ course, but you've found that you still can't follow your colleagues when they're describing their C++ designs and code
You're an experienced C or Java programmer, but you don't yet have the experience to develop nuanced C++ code and designs
You're a C++ expert, and you're looking for an alternative to answering the same questions from your less-experienced colleagues over and over again
C++ Common Knowledge covers essential
but commonly misunderstood topics in
C++ programming and design while
filtering out needless complexity in
the discussion of each topic. What
remains is a clear distillation of the
essentials required for production C++
programming, presented in the author's
trademark incisive, engaging style.
Here is a link to a question with answers that should help you.
https://stackoverflow.com/questions/1227764/i-need-to-improve-my-c-skills-fast-is-this-realistically-possible/1227805#1227805
For effective stuff you can find online Cplusplus.com has a pretty good reference and information.
If you can find the book "C++ Common Knowledge" (Stephen Dewhurst) at the library or cheaply online, I would add that to the list posted on the StackOverflow link above as well as "The C++ Programming Language" (Stroustrup). Going through the questions under the C++ tag right here on SO should give you some good pointers and code examples to get you on your way.
Here's a list of good C++ books which teach you C++ rather than basics of programming.
Sit down and write some C++ code.
I just purchased C++ GUI Programming with Qt4 and after reading the code samples in this book I'm beginning to realize that my knowledge of C++ is incomplete. I learned C++ two years ago from online tutorials and a couple of ebooks I downloaded, and it turns out none of these resources were good enough. Since then I haven't touched the language and have been using Python instead.
Now I'm thinking of purchasing a good book on C++ that covers advanced topics, and the one I have in mind is Bruce Eckel's Thinking in C++ (both volumes). I know they are available for free on the web, but I really can't stand reading books on a laptop screen.
Since C++0x might be out pretty soon, is it wise to go ahead and spend cash on these books? Will C++0x break backwards compatibility? Volume 2 covers features like multithreading, templates etc. Would any of these features change significantly in C++0x?
I wouldn't hold my breath for C++0x. I doubt it will be out by the end of this decade. Even when it will be out, you should probably count a year or so for compilers to implement it. Learn the fundamentals now, and it should be relatively easy for you to learn most of the new features when the standard is out. The Standards Committee is known for its efforts to maintain backward compatibility.
I personally check with the evolution of the standard from time to time, just out of curiosity. Subscribe to Herb Sutter's blog feed and look for Standard updates.
My personal favourite advanced C++ book is Bjarne Stroustrup's The C++ Programming Language, 3e. It is the one single C++ book from which I think I learnt the most, with respect to language and STL details. Scott Meyers' books helped clarify a lot of things too. Meyers writes in a very readable language (English, I believe), and often what would happen is that I'd read an entire Item from Meyers' book, and then find the same information in Stroustrup's book condensed into a single sentence or so. That is to say Meyers' books are extremely useful in getting your attention to interesting details.
As for the changes I expect for threading, I think there going to be two new libraries for this purpose in the standard. Concepts are an even bigger change coming, and they are somewhat related to templates. Up until now we had concepts in the STL, but these were conventions; an algorithm would make assumptions about a type you pass to a template, and you'd know to pass the correct "type of type" because of the conventions. This implied terribly error messages, the STL template errors we all know and "love". Concepts will help solve these. There are other improvements (complexities) to the language. Herb Sutter talks about them a lot.
It is certainly wise to buy the book. C++1x will hardly break with previous code. Nearly everything you learn is also possible with the next C++, and it will greatly help you understand the need of why C++1x will introduce what feature. For example, why will it have variadic templates, and why those concepts?
Even if the backward compatibility is broken on some features, the biggest part should be still usefull.
Furthermore, the first books on C++Ox might not be the best ones.
I would prefer a very good book on C++ to a book on C++Ox.
I would definitely go for buying the books
Those from Eckel are really good books, and I really recommend them.
It will take several years for compilers to catch up with new features introduced with C++0x (just look how was with template support!)
It will take even more years for projects to start using them
Finally, although I do not know with detail the3 changes introduced with the new release of the language, the C++ committee has always been very conservative on backward compatibility, therefore you should do not have any risk of learning something will be obsolete soon.
I'd echo the recommendation to get the Bjarne Stroustrup book "The C++ Programming Language
(Third Edition and Special Edition)" http://www.research.att.com/~bs/3rd.html in addition to any other book you may be interested in, if you can afford multiple books. If you can afford only one and have mastered the basics (as you have) then I'd probably learn towards the Stroustrup book. You can't go past getting the facts from the man himself.
You can track developments in C++0x here:
http://www.research.att.com/~bs/C++0xFAQ.html
if you are interested. As previously commented, I wouldn't hold my breath if I were you.
You might try a site like Safari Books Online to keep up-to-date with technical and programming books. I've bought several Ruby- and Ruby on Rails-related books in the past and they're now much less useful because the stuff in them is deprecated.