Structured Programming

Computer terminology
Collection
zero Useful+1
zero
Structured programming is to modular Features and Processing Design oriented detailed design Basic principles of. Structured programming is Procedural programming A subset of the, which uses the Logical structure To make understanding and modification more effective and easier.
Chinese name
Structured Programming
Foreign name
structured programming
Proposer
E.W.Dijikstra
Proposed time
1965
Purpose
Improve program execution efficiency
Principles
Program=(algorithm)+(data structure)

content validity

Announce
edit
The "structure oriented" programming method is Structured programming method , Yes“ Process oriented ”The method is improved, and the structure will software system It is divided into several functional modules, each module is programmed separately as required, and then connected by each module to form a corresponding software system. This method emphasizes the structure of the program, so it is easy to read and understand. This method has clear ideas and standard practices, and is favored by designers.
The idea of Structured Programming (SP) was first developed by E W. Dijikstra put forward in 1965 that the idea of structured programming really improves the efficiency of program execution [1] programmatic Error rate and maintenance cost Greatly reduce Structural programming It is a kind of principle and method for program design. According to this principle and method, we can design a structured program with clear structure, easy understanding, easy modification and easy verification. The goal is to make the program have a reasonable structure to ensure and verify the correctness of the program, so as to develop a correct and reasonable program.

principle

Announce
edit
Structured programming adopts top-down Gradual refinement The design method of control structure It is connected and has only one inlet and one outlet.
The principle of structured programming can be expressed as: program=(algorithm)+( data structure )。
The algorithm is an independent whole, and the data structure (including data type And data) is also an independent whole. The two are designed separately, focusing on algorithms (functions or processes).
along with computer technology The development of, software engineer More and more attention is paid to the expression of the overall relationship of the system, so data model Technology (treat data structure and algorithm as an independent functional module ), this is Object-oriented programming The rudiment of. [2]

Basic structure

Announce
edit

Sequential structure

Sequential structure Indicates that the operations in the program are in accordance with their occurrence order Sequential execution Of.

Select Structure

Select Structure It indicates that there is a branch in the processing step of the program, and it needs to select one of the branches for execution according to a specific condition. The selection structure has three forms: single selection, double selection and multiple selection.

Cyclic structure

Cyclic structure It indicates that the program repeatedly executes one or some operations, and the loop can not be terminated until a condition is false (or true). The most important thing in the loop structure is: under what circumstances do you execute the loop? Which operations need to be executed circularly? There are two basic forms of circular structure: Current cycle And until type cycle.
Current cycle : indicates that the condition is judged first, the loop body is executed when the given condition is met, and the process automatically returns to the loop inlet at the loop terminal; If the conditions are not met, exit the loop body and directly reach the process outlet. Because it is "execute cycle when conditions are met", that is, judge before execute, it is called current cycle.
Until type cycle : indicates that the loop body is executed directly from the structure inlet, and the condition is judged at the loop terminal. If the condition is not met, return to the inlet Continue execution The loop body, until the condition is true, exits the loop and reaches the process outlet. It is executed first and then judged. Because it is "until the condition is true", it is called a until type cycle.

Design method

Announce
edit

top-down

In programming, the overall design should be considered first, and then the details; Consider the global goal first, then the local goal. Don't pursue too many details at the beginning. Start from the top overall goal to design and gradually make the problem concrete.

Gradually refine

yes Complex problems , some sub goals should be designed as a transition, and gradually refined.

modularization

Structured Programming
A complex problem must be composed of a number of simpler problems. modular The transformation is to solve the problem of Goal decomposition Is a sub goal, which is further decomposed into specific small goals, and each small goal is called a module.
Restricted use goto Statement   Structured programming method The origin of goto statement Understanding and debate. The positive conclusion is that GOTO statements are often needed at the abnormal exits of blocks and processes, and GOTO statements will make the program execution more efficient; GOTO statements are often useful when synthesizing program targets, such as GOTO for return statements. The negative conclusion is that GOTO statements are harmful and are the cause of program confusion. The quality of the program is similar to the number of GOTO statements inverse ratio , should be in all Advanced Programming Language Cancel the GOTO statement in. After the GOTO statement is cancelled, the program is easy to understand, debug, maintain, and perform Proof of correctness As the conclusion of the debate, Knuth published a convincing summary in 1974 and confirmed that:
(1) GOTO statements are really harmful and should be avoided as far as possible;
(2) It is not a wise way to completely avoid using GOTO statements. Using GOTO statements in some places will make the program flow clearer and more efficient;
(3) The focus of the debate should not be on whether to cancel GOTO statements, but on what program structure to use. The most important thing is to improve the procedure Clarity Targeted Structured approach GOTO statements are restricted in.

Structured coding

The so-called coding is to use the designed algorithm computer language That is, write the computer correctly according to the refined algorithm program Structured languages (e.g Pascal , C, QBASIC, etc.) Basic structure The corresponding statement.

Existing problems

Announce
edit
1. Poor reusability of software
Reusability refers to the nature that the same thing can be repeatedly used without modification or slight modification. Software reusability is software engineering One of the goals pursued. If the reusability of software is poor, the cost of software is relatively high.
2. Software Maintainability difference
Software engineering emphasizes the maintainability of software. Emphasize the importance of documentation. Specify final software product It should be composed of complete and consistent configuration components. stay Software development process Medium. Always emphasize the readability Modifiability and Testability It is important for software quality index Practical proof The cost and cost of software developed by traditional methods are still very high during maintenance. The reason is poor modifiability and difficult maintenance. This leads to poor maintainability.
3. The software developed cannot really meet the needs of users
Structured approach Developing large-scale software systems involves knowledge in various fields. When developing a system with fuzzy or dynamic requirements, the developed software system can not really meet the needs of users. [3]

Advantages and disadvantages

Announce
edit

characteristic

Structured program Any basic structure in has a unique entry and exit, and the program does not appear Dead cycle There is a good correspondence between the static form of the program and the dynamic execution process.
because modular They are independent of each other, so when designing one module, they will not be involved by other modules. Therefore, the original complex problems can be simplified into a series of simple module designs. 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.
From the point of view of structured programming, any algorithm function can be Program module The combination of three basic program structures: Sequential structure , Select Structure and Cyclic structure To achieve.
The basic idea of structured programming is to adopt the programming method of "top-down, gradual refinement" and“ Single entry and single exit ”Control structure of. The top-down and gradually refined programming method starts from the problem itself, and after gradually refining, the steps to solve the problem are decomposed into the basic program structure modular Structured program composed of block diagram The idea of "single entry and single exit" holds that a complex program is composed of three basic program structures: sequence, selection and loop through combination and nesting Neotectonics The program must be a single entry and single exit program. Therefore, it is easy to write programs with good structure and easy debugging.

advantage

① The overall idea is clear and the goal is clear;
② The design work is very phased, which is beneficial to system development Of Overall management And control;
③ On systems analysis Can be diagnosed Original system Problems and structural defects in.

shortcoming

① User requirements are difficult to systems analysis The accurate definition of the phase causes many problems when the system is delivered for use;
② Use the results of each stage of system development to control, which can not meet the requirements of changes in things;
③ System development Long cycle