Chapter 26. Program Design

If carpenters made houses the way programmers design programs, the first woodpecker to come along would destroy all of civilization.

Traditional computer proverb

Now that you’ve got the mechanics of programming down, we’ll take a look at how to design good code. Creating a well-designed program is both a science and an art form. There is lot of science involved in the techniques and rules used to produce a good design. Your artistic side comes in to play when you use these rules to lay out a well-designed and beautiful program.

Design Goals

Before we decide how to make a well-designed program, we need to define what we mean bywell designed. Different people value different things. But in most cases, people tend to value the same attributes. So let’s explore what people value in a program:

Reliability

People want a program that works. Crashes are extremely frustrating. They cost people time, cause data loss, and in extreme cases can cost people’s lives. So reliability is extremely important.

Economy

Most people, especially managers, don’t like to spend money. They want the cheapest software possible.

Ease of use

No program is useful if people can’t use it. This may sound a bit obvious, but lots of programmers suffer from the “added feature disease” where they want to cram as many features as possible into their code. The result is something overly complex and difficult to use: in other words, a badly designed program.

Design Factors

Now that we know what we want ...

Get Practical C++ Programming, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.