30.8 The Ten Commandments for C++ Programmers
These commandments were written by Phin Straite.
Thou shalt not rely on the compiler default methods for construction,
destruction, copy construction, or assignment for any but the
simplest of classes. Thou shalt forget these "big
four" methods for any nontrivial class.
Thou shalt declare and define thy destructor as virtual such that
others may become heir to the fruits of your labors.
Thou shalt not violate the "is-a"
rule by abusing the inheritance mechanism for thine own twisted
perversions.
Thou shalt not rely on any implementation-dependent behavior of a
compiler, operating system, or hardware environment, lest thy code be
forever caged within that dungeon.
Thou shalt not augment the interface of a class at the lowest level
without most prudent deliberation. Such ill-begotten practices
imprison thy clients unjustly into thy classes and create unrest when
code maintenance and extension are required.
Thou shalt restrict thy friendship to truly worthy contemporaries.
Beware, for thou art exposing thyself rudely as from a trenchcoat.
Thou shalt not abuse thy implementation data by making it public or
static except in the rarest of circumstances. Thy data are thine own;
share it not with others.
Thou shalt not suffer dangling pointers or references to be harbored
within thy objects. These are nefarious and precarious agents of
random and wanton destruction.
Thou shalt make use of available class libraries as conscientiously
as possible. Code reuse, not just thine own but that of thy clients
as well, is the Holy Grail of OO.
Thou shalt forever forswear the use of the vile
printf/scanf, rather favoring
the flowing streams. Cast off thy vile C cloak and
partake of the wondrous fruit of flexible and extensible I/O.
|