Friday, 23 March 2012

Choosing a dialect of C++

The C++ language, which inevitably includes not just its own standard library but common additional libraries like Boost and CGAL, is huge.  It supports a wide variety of often partially incompatible programming styles, everything from "C with a working const keyword" to template metaprogramming to exception-based control flow.  Since one of my goals with Tungsten is to learn "modern idiomatic C++", I need to narrow down my focus and pick one style to focus on.

I've chosen the dialect of C++ described in the Google C++ Style Guide.

Coming back to C++ with about a decade of experience as a (sometimes elitist) C programmer, I see plenty of potential for confusion with a lot of the "automagical" features in C++, such as implicit type promotion, default implementations for copy constructors (and their not-always-obvious invocation in pass-by-value function calls), and global/static initialization order ambiguity.  Google's style guide describes a set of conventions for writing C++ code that seems to avoid or at least mitigate many of the potentially subtle bugs inherent in those features.  Like warning signs on power tools, I have to assume that Google's C++ style guide was written in blood.

Beyond the GCSG is Marshall Cline's C++ FAQ Lite.  I remember reading that site back in the days before cable/DSL.  It's more prescriptive than I remember, and when it conflicts with the GCSG I'm probably going to go with Google's wisdom, but it covers a lot of ground.

Finally, the C2 Wiki is probably the smartest collection of programming wisdom on the 'net, so I'll try to refer to their C++ Category as much as possible without getting overwhelmed by options.

No comments:

Post a Comment