Here we list, semi-explicitly, the style expected for C++ code for Wilcox Development Solutions (see also: Effective C++, Exception C++ books, etc)
Make deconstructors virtual only when class is intended for subclassing (RPW wants a keyword like Java's final keyword) (but see Stroustrup's reasoning against it). Stroustrup also has a good rule of thumb for when you need a virtual deconstructor: Whenever the class has at least one virtual function.
Use Headerdoc to document classes
- Just because you have multiple inheritance doesn't mean you have to use it (RPW wants a keyword like Java's interface keyword)
RPW prefers putting the beginning curly brace on a separate line from the statement it belongs with
if (true) { ... }- Use m_varname for member variables
- Templates are one of those "A little goes a long ways" things
- Timestamp your comments with COMPANY INITIALS + initials + datestamp (USA format with dashes, include century). Example: WD-rpw 05-24-2007 (why century? So people can figure out where the year is, and thus the date format. Especially important in years before 2013, where 12-05-11 is totally ambiguous as to if the date is in European or US format) (date +%m-%d-%Y)
- Prefer C99's int8_t, int16_t, int32_t, and int64_t instead of char, short, long, and long long; uint8_t, uint16_t, uint32_t and uint64_t for the unsigned types. This ensures you know exactly how many bytes you're dealing with.
Use CoreFoundation Guidelines (Create vs Get) to determine if an object needs to be deleted by the caller (as in the former case) or is deleted automatically (as in the latter case). (Although, RPW may prefer New instead of Create - to mimic the new C++ keyword).
- When you don't know something, look it up in every book we have and reference them one to another.
RIT has a good (well, maybe I'm bias) C++ style guide. There's some sillyness in there (especially some of the items in their "Special C++ Requirements" section), but document is good in general - although the items above should override recommendations given in that document. Google has their own C++ style guide, and it's worth pursuing for more thoughts on this topic.
Comments:
Add comments by visiting: Cpp Information/WDStyle/Comments