1.7.6 In a Nutshell

The discussion of good programming style may be summarized with the following guidelines.

1. Take care to present programs well.

Don't choose a name without a purpose.

Don't leave a component's purpose unspecified.

Descriptions should be simple even if tasks are not.

2. Communicate well.

Store data only where it is needed (use local variables).

Pass information explicitly when needed elsewhere (use parameters).

Avoid side effects.

3. Use data abstraction.

This is the basic way to make programs independent of data implementation, and it makes implementation changes easier and more reliable.

4. Functionally modularize programs.

Functions should execute a simple, narrowly defined task.

It should be possible to determine what a function does by looking only at it.

Changes to a function should not necessitate changes in other functions.

Prevent unreasonable input and output data by defensive programming.

5. Use debugging aids.

Also verify your programs.

Of course, strict adherence to rules may not always be possible or even yield the best results. Knowing how or to what extent to apply programming rules comes only from experience in using them and in studying their effects.