C++ Programming Style Preface
Next toc
Prev: abstract
Up: top
Almost two decades after the publication of Kernighan and Plauger's classic,
The Elements of Programming Style, its compact set of rules remains the best
general guidance on good programming. Today, however, our programs are larger
and our programming languages have changed. We now care as much about how the
components of a program fit together as we do about the algorithms and data
structures used in each component. DeRemer and Kron coined the terms
programming-in-the-large and programming-in-the-small to make a distinction
between the large-scale and small-scale aspects of programs. By
programming-in-the-small, they meant dealing with components of a program
that are one to a few pages long - the size of a typical C++ class. By
programming-in-the-large, they meant the structuring of in-the-small
components into a program - in C++ terms, dealing with relationships between
classes. Kernighan and Plauger concentrated their work on the issues of
programming-in-the-small. Their advice about programming-in-the-large is
sound, but minimal
Modularize. Use subroutines.
This book addresses programming style, with more emphasis on
programming-in-the-large, and is restricted to the domain of C++ programs. It
is written for the programmer who has learned the mechanics of C++, but is
experiencing difficulty in applying the language features - particularly the
object-oriented features - to programming problems. Though the discussion is
limited to C++, many of the observations about programming are true of other
languages. I leave the treatment of language-independent style in-the-large
to more ambitious authors.
I have adopted Kernighan and Plauger's method of distilling rules of
programming style from the critical reading and rewriting of programs. All
the programs used here are taken from textbooks, magazine articles and
tutorials on C++ programming. None was created artificially for this work.
Some programs are presented exactly as originally published, while others
have been altered cosmetically. The alterations range from the correction of
in-the-small bugs, which would only distract, to structure-preserving
transformations of programs for which copyright was not obtained.
The spirit in which to approach the material is that of an egoless code
review. We all learn by reading and reviewing each other's programs. The
material is not a criticism of individual programmers - it seeks only to
differentiate between good and bad programs. No doubt the programs that are
presented here as better versions have their own shortcomings. The reader
is encouraged to examine these programs critically, looking for further
improvements in programming style.
automatically generated by info2www version 1.2.2.8