Good Programming Practices
- Programs and subprograms should be well structured.
- · Use a modular approach for a complex problem.
- · Use the basic control structures when developing each code segment.
- · Sequence, selection, repetition
- · Use local variables within subprograms.
- · Use parameters to pass information to and from subprograms.
- · Avoid global Variables.
- · To prevent arguments that should not be modified by a subprogram, declare the corresponding parameters to be value parameter or constant reference parameters rather than reference parameters.
- · Strive for simplicity and clarity.
- · Identify any preconditions (assumptions) and postconditions a program or subprogram has, and check them.
- All source code should be documented.
- · Each program should include opening documentation.
- · Each subprogram should be documented in a manner similar to programs.
- · Comments should be used to explain key code segments and / or segments whose purpose or design is not obvious.
- · Use meaningful identifiers.
- Source code should be esthetic; it should be formatted in a style that enhances its readability.
- · Put each statement of the program on a separate line.
- · Use uppercase and lowercase letters in a way that contributes to program readability.
- · Put each { and } on separate lines.
- · Align each { and corresponding }.
- · When a statement is continued from one line to another, indent the continued line(s).
- · Align the identifiers in each constant and variable declaration, placing each on a separate line.
- · Insert blank lines between declarations and statements and between blocks of statements to make clear the structure of the program.
- · Separate the operators and operands in an expression with spaces to make the expression easy to read.
- · Declare constants at the beginning of a function. Declare variable near their first use.
- · Label all output produced by a program.