April 90 - UNOFFICIAL C++ STYLE GUIDE
UNOFFICIAL C++ STYLE GUIDE
DAVID GOLDSMITH AND JACK PALEVICH
C++ is fast emerging as the premier object-based language of the 1990s. Its
expressive power combined with its down-and-dirty C heritage makes it a natural
choice for writing Macintosh applications. But beware: all is not sweetness and light.
Harnessing C++'s power without getting tripped up by some of its less savory features
isn't all that easy. Here are guidelines that make it easier to write, debug, and change
C++ programs.
When we first started using C++ several years ago, we learned the hard way--by
trial and error--a lot of what we're about to tell you. After thousands of hours of C++
programming, we've formed strong opinions about the best way to use C++. In this
unofficial style guide we tell you which features to use and which ones to avoid.
Following our techniques will lead to programs that are easier to write, debug, and
change. You may not agree with all of our guidelines--some are more a matter of taste
than of science--but we hope you'll find them useful and enlightening.
PART 1: STYLE
In this part you'll find fairly simple advice on formatting source files. Even if you
prefer to use a different style in your own work, you may be interested to see how we
handle these standard matters of style.
SOURCE FILE CONVENTIONS
Use the following conventions to keep your source files easy to read, easy to use, and
legally protected.
Include a copyright notice. To protect your intellectual property rights, include
the following line at the front of every file you create:
// Copyright © 1990 ~~~Your name or company~~~.
// All rights reserved.
You can make the © by typing Option-g. The "All rights reserved" is specifically for
our foreign friends. (We bet you thought all you had to say was "Copyright." Ha!) In
addition, any binary files you ship should contain a copyright notice somewhere.