Structured programming is tomodularFeatures andProcessingDesign orienteddetailed design Basic principles of.Structured programming isProcedural programmingA subset of the, which uses theLogical structureTo make understanding and modification more effective and easier.
The "structure oriented" programming method isStructured programming method, Yes“Process oriented”The method is improved, and the structure willsoftware systemIt 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 EW. Dijikstra put forward in 1965 that the idea of structured programming really improves the efficiency of program execution[1]。programmaticError rateandmaintenance cost Greatly reduceStructural programmingIt 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-downGradual refinementThe design method ofcontrol structureIt 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 (includingdata typeAnd data) is also an independent whole.The two are designed separately, focusing on algorithms (functions or processes).
Select StructureIt 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 structureIt 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 cycleAnd 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 inletContinue executionThe 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
yesComplex 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.modularThe transformation is to solve the problem ofGoal decompositionIs a sub goal, which is further decomposed into specific small goals, and each small goal is called a module.
Restricted usegoto Statement Structured programming methodThe origin ofgoto 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 statementsinverse ratio, should be in allAdvanced Programming LanguageCancel the GOTO statement in.After the GOTO statement is cancelled, the program is easy to understand, debug, maintain, and performProof 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 procedureClarityTargetedStructured approachGOTO statements are restricted in.
Structured coding
The so-called coding is to use the designed algorithmcomputer languageThat is, write the computer correctly according to the refined algorithmprogram。Structured languages (e.gPascal, C, QBASIC, etc.)Basic structureThe 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 issoftware engineeringOne of the goals pursued.If the reusability of software is poor, the cost of software is relatively high.
Software engineering emphasizes the maintainability of software.Emphasize the importance of documentation.Specify finalsoftware product It should be composed of complete and consistent configuration components.staySoftware development processMedium.Always emphasize the readabilityModifiabilityandTestabilityIt is important for softwarequality 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 approachDeveloping 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 programAny basic structure in has a unique entry and exit, and the program does not appearDead cycle。There is a good correspondence between the static form of the program and the dynamic execution process.
becausemodularThey 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 beProgram moduleThe combination of three basic program structures:Sequential structure, Select Structure andCyclic structureTo 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 structuremodularStructured program composed ofblock 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 nestingNeotectonicsThe 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;