Pete Vidler wrote:
> I'm wondering if there is a compilation of C++ guidelines out there
> anywhere. Here are some of the ones I've picked up so far (as examples):
>
> - Functions should fit on one screen, from various sources.
Functions should have 1 to 5 activities. In higher level languages this
translates to 1 to 5 statements, but C++ requires a lot of rigging and
piping.
> - Non-leaf classes should be abstract (have pure virtual methods), from
> More Effective C++, Item 33.
The corpus of Addison Wesley [Longman]'s C++ and theory books form the
pinacle of known style. Try /Design Patterns/, /Large Scale C++ Software
Design/, and /Refactoring/.
> - Virtual methods should be private by default and protected if they
> need access to a base classes version (except for the destructor, of
> course), from http://www.gotw.ca/publications/mill18.htm.
Also try /Exceptional C++/, by Herb Sutter.
> - Header files should be self contained, from various sources.
The implication here is you can always add a new #include "thing.h", and it
takes care of itself. You never need to add another #include above it.
/Large Scale/ covers this in great detail.
> - Destructors for base classes should be either virtual or protected.
Never heard of the "protected" one.
> I think I've probably missed (or never heard of) quite a few more.
> Anyone know where I can find such things? Or have some guidelines of
> their own to share?
These guidelines occupy a spectrum. At one end, we have requirements that
C++'s minimal expression enforces. Thou shalt make all destructors virtual
unless profiling reveals the need to remove a class's 'vtable'. At the other
end we have team specific patterns and behaviors. For example, one team may
adopt STL for all collection classes, and another may have an alternative
library, hence should not use STL. But we should recommend STL when writing
books for AW.
--
Phlip
http://www.xpsd.org/cgi-bin/wiki?Tes...UserInterfaces