Fortune Telling Collection - Zodiac Analysis - Principles of structured programming

Principles of structured programming

Structured programming has four main principles:

1. Top-down: When programming, consider the whole first, then the details; Consider the global goal first, then the local goal. Don't pursue too many details at the beginning, start with the highest overall goal and gradually concretize the problem.

2. Gradual refinement: For complex problems, we should design some sub-goals as a transition and gradually refine them.

3. Modularization: A complex problem must be composed of several relatively simple problems. Modularization is to decompose the overall goal of a program into sub-goals, and then further decompose it into specific small goals, and call each small goal a module.

4. Restrict the use of goto statements

The origin of structured programming method comes from the understanding and debate of GOTO statement. The positive conclusion is that GOTO statements are often needed at the abnormal exits of blocks and processes, which will make the program execution more efficient; GOTO statements are often useful when synthesizing program goals, such as using GOTO in return statements.

The negative conclusion is that GOTO statement is harmful and the bane of program confusion. The quality of the program is inversely proportional to the number of GOTO statements, and all high-level programming languages should cancel GOTO statements. After canceling the GOTO statement, the program is easy to understand, debug, maintain and prove its correctness. As the conclusion of the argument, Knuth published a convincing summary in 1974, and cancelled the GOTO statement.

Extended data:

Structured program divides the software system to be developed into several independent modules with modular design as the center.

Structured programming was proposed by Dykstra in 1969. Centered on modular design, it divides the software system to be developed into several independent modules, which makes the work of each module simple and clear, and lays a good foundation for designing some larger software.

Because the modules are independent of each other, when designing a module, it will not be implicated by other modules, so the original complex problem can be simplified into the design of a series of simple modules. The independence of modules also brings a lot of convenience for expanding existing systems and establishing new systems, because we can make full use of existing modules for building block expansion.

References:

Baidu Encyclopedia Structured Program