Best Practices and Debugging

Programs are developed, maintained, and used by people for different purposes so programs have to be written well. Program style can affect the determination of program correctness. Duplicated code can make it harder to reason about a program. Duplicated code should be abstracted and implemented as a function or procedure.

Meaningful names for variables and functions/procedures help people better understand programs. Longer code blocks are harder to reason about than shorter code blocks in a program.

Locating and correcting errors in a program is called debugging the program. Knowledge of what a program is supposed to do is required in order to find most program errors. Examples of intended behavior on specific inputs help people understand what a program is supposed to do. Visual displays (or different modalities) of program state can help in finding errors.

As part of the programming process, programmers justify and explain a program’s correctness. Justification can include a written explanation about how a program meets its specifications. Correctness of a program depends on correctness of program components, including code blocks and procedures. An explanation of a program helps people understand the functionality and purpose of a program. The functionality of a program is often described by how a user interacts with the program. The functionality of a program is best described at a high level by what the program does, not at a lower level of how the program statements work to accomplish this.