1 - Introduction
Published online by Cambridge University Press: 01 September 2009
Summary
style: 1b. the shadow-producing pin of a sundial. 2c. -the custom or plan followed in spelling, capitalization, punctuation, and typographic arrangement and display.
—Webster's New Collegiate DictionaryThe syntax of a programming language tells you what code it is possible to write—what machines will understand. Style tells you what you ought to write—what humans reading the code will understand. Code written with a consistent, simple style is maintainable, robust, and contains fewer bugs. Code written with no regard to style contains more bugs, and may simply be thrown away and rewritten rather than maintained.
Attending to style is particularly important when developing as a team. Consistent style facilitates communication, because it enables team members to read and understand each other's work more easily. In our experience, the value of consistent programming style grows exponentially with the number of people working with the code.
Our favorite style guides are classics: Strunk and White's The Elements of Style and Kernighan and Plauger's The Elements of Programming Style. These small books work because they are simple: a list of rules, each containing a brief explanation and examples of correct, and sometimes incorrect, use. We followed the same pattern in this book. This simple treatment—a series of rules—enabled us to keep this book short and easy to understand.
Some of the advice that you read here may seem obvious to you, particularly if you've been writing code for a long time. Others may disagree with some of our specific suggestions about formatting or indentation.
- Type
- Chapter
- Information
- The Elements of C++ Style , pp. 1 - 3Publisher: Cambridge University PressPrint publication year: 2004