Pascal. Principles of structured programming. Modular software development

Principles of structured programming. Modular software development


Contents


Search other websites:




1. The need to structure programs. Components of a structured approach to programming

Creation of large complex programs for solving typical problems requires significant intellectual costs from programmers. To increase the efficiency of compiling such programs, a structured approach to programming is used, which allows you to create large programs with virtually no errors and on schedule. The goal of the structured approach is to design programs in such a way that they can be used and modified without the involvement of authors. This helps to reduce the cost of creating and further use of programs during operation.

A structured approach to programming has three parts:

  • top-down development;
  • structured programming (coding);
  • end-to-end control (testing).

  

2. Top-down development

In top-down development, design and programming is done in a top-down manner. This method involves first defining the problem in general terms, and then gradually refining its structure through the step-by-step introduction of small details. Thus, the original problem is split into a number of simpler subtasks.
Each subtask corresponds to its own program module, independent of any other subtask, which is a functionally independent part of the program – a set of several program statements. In top-down development, a sequential detailing of the project is carried out from high-level modules to low-level modules. For each module, an algorithm for solving the problem, areas of admissible and possible initial values of variables are determined.

Most often, a module implements one function and then returns control to the calling module. It is forbidden to terminate the execution of the entire program in the called module, the choice to execute it is accepted only by the calling module.
Basic requirements for the program module: the presence of only one input and one output; limited module size.

  

3. Structured programming (coding)

Structured programming is a method of writing well-structured programs of arbitrary size and complexity based on basic control structures. These include sequential execution, branching and loop. Basic control structures make the program easier to understand and test because the entire flow of control in a program runs from structure to structure from top to bottom.

A list of the main control structures is given below.

1. Process, following (Figure 1).

Programming. Geometric designation of the process

Figure 1. Geometric designation of the process

2. Branching, solution (Figure 2). If Condition is met, then Statement 1 is executed. Otherwise, Statement 2 is executed.

Programming. The geometric designation of branching

Figure 2. The geometric designation of branching

3. Loop

Programming. The geometric designation of branching

Figure 3. The geometric designation of branching

  

4. Testing

Testing (end-to-end control) is the process of finding errors in a program, which is planned before starting programming. It is prudent to conduct top-down testing in an effort to achieve the minimum number of test cases. First, the goals of testing are determined. They can be all kinds of checks: the reaction of the program to invalid input data, the interaction between modules, the operation of the program with the minimum and maximum input data.

Testing is considered complete when all the necessary checks have been made for the compliance of the program with the goals of its development and all found errors are neutralized at the debugging stage using special applications – debuggers.

In modern systems for visual application development, powerful tools are designed for program debugging. For example, in the Lazarus system, a separate subsection from the Run menu is reserved for step-by-step program debugging (Figure 4).

Debug commands in Lazarus system

Figure 4. Debug commands in Lazarus system: “Step Into”, “Step Over”, “Step Out”, “Step over to Cursor”

In the Delphi development system, the debug command menu looks something like the one shown in Figure 5.

Delphi system debug commands

Figure 5. Delphi system debug commands: “Step Over”, “Trace Into”, “Trace To Next Source Line”, “Run To Cursor”

  


Related topics