The Ten Commandments for C++ Programmers

  1. Thou shalt not rely solely on the compiler-generated default methods for construction, destruction, copy construction, or assignment for any but the simplest of classes. Thou shalt scrupulously forge these “foremost four” methods for any non-trivial class, yea, even though thy implementation be but trivial. Further, thou shalt declare and define thy destructor as virtual such that others may become heir to the fruits of your labors with ease.
  2. Thou shalt not violate the “is-a” rule by abusing the inheritance mechanism for thine own twisted perversions. Denounce with vigor the primordial OO publications wherein this sinful behavior was epitomized.
  3. Thou shalt not rely on any implementation-dependent behavior of a compiler, operating system, nor hardware environment, lest your code be forever caged within that dungeon whilst others” code scampers unfettered through architectures as yet undreamt of.
  4. Thou shalt not augment the interface of a class at the “concrete” level without most prudent deliberation. Such ill-begotten practices imprison thy clients unjustly into your classes, and foment unspeakable unrest when code maintenance and extension are required.
  5. Thou shalt restrict thy friendship to truly worthy contemporaries. Beware, for thou art exposing thyself wellnigh as rudely as from a trench coat.
  6. Thou shalt not abuse your implementation data by making it public or static except in the rarest of circumstances. Thy bits are thine own; share them not with others.
  7. Thou shalt not suffer dangling pointers or references to be harbored within your objects. These are nefarious and precarious agents of random and wanton destruction. While ye may escape their wrath, thy fellow programmer may verily be ravaged by them.
  8. Thou shalt make use of available class libraries as conscientiously as possible. Code reuse, not just thine own but that of your clients as well, is the holy grail of OO. A seemly set of class libraries will put you on a path where you may be enlightened.
  9. 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 IO.
  10. Thou shalt avoid designing “big” classes–classes with both an unseemly abundance of instance data and tortuosly complicated interfaces. Such accursed classes are the unclean and unwieldy result of poor design. Be chastened, seek truth, and design again, that thy userid may be enshrined among the enumeration of the most purely virtuous.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.