November 2011
Intermediate to advanced
206 pages
4h 32m
English
Content preview from The Art of Readable Code

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
Start your free trial


Chapter 4. Aesthetics

A lot of thought goes into the layout of a magazine—the length of the paragraphs, the width of the columns, the order of the articles, and what goes on the cover. A good magazine makes it easy to skip around from page to page, but also easy to read straight through.
Good source code should be just as “easy on the eyes.” In this chapter, we’ll show how good use of spacing, alignment, and ordering can make your code easier to read.
Specifically, there are three principles we use:
Use consistent layout, with patterns the reader can get used to.
Make similar code look similar.
Group related lines of code into blocks.
Why Do Aesthetics Matter?

Imagine if you had to use this class:
class StatsKeeper { public: // A class for keeping track of a series of doubles void Add(double d); // and methods for quick statistics about them private: int count; /* ...