Solution

Definition
A C++ program is a set of instructions of the C++ programming language that can be interpreted by a computer into a sequence of basic operations that the computer can perform.

Axiom
A C++ program consists of a set of global declarations/definitions and several nested groups of instructions. Each group of instructions is delimited by curly brackets ({ }).

Definition
The rank of a group of instructions in a C++ program is the nesting level of the group in the program. Global declarations/definitions are defined to be at rank 0.

Definition
Consider a C++ program with instructions $ I_1,\ldots,I_n$ . For a given $ K>0$ , a group of $ t$ instructions $ (I_h,\ldots,I_{h+t})$ at rank $ r$ in a C++ program is well-$ K$ -indented if:

  1. no two instructions are on the same line of text;
  2. the opening curly bracket is on a line of text above $ I_h$ and the closing curly bracket is on a line of text below $ I_{h+t}$ ;
  3. $ I_{h-1}$ (the last instruction at rank $ r-1$ before the beginning of the group) starts $ K$ columns of text before $ I_h$ ;
  4. the closing curly brace of the group is aligned with instruction $ I_{h-1}$ (in other words, it is positioned $ K$ columns of text before $ I_{h+t}$ ).

Definition
A C++ program is well-indented if there is an integer $ K>0$ such that (a) the global declarations/definitions start at column 0, and (b) each of its instruction groups is well-$ K$ -indented.

Fact
Usual values for $ K$ are 2, 4, 8. In this course, the value $ K=2$ is favoured as it allows for a greater number of nesting levels to be displayed in 80 characters (the usual screen width on UNIX systems).

Leo Liberti 2008-01-12