9
Structured Programming structured programming: A technique for organizing and coding computer programs in which a hierarchy of modules is used, each having a single entry and a single exit point, and in which control is passed downward through the structure without unconditional branches to higher levels of the structure. Three types of control flow are used: sequential, test, and iteration.

Structured Programming structured programming: A technique for organizing and coding computer programs in which a hierarchy of modules is used, each having

  • View
    212

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Structured Programming structured programming: A technique for organizing and coding computer programs in which a hierarchy of modules is used, each having

Structured Programming

• structured programming: A technique for organizing and coding computer programs in which a hierarchy of modules is used, each having a single entry and a single exit point, and in which control is passed downward through the structure without unconditional branches to higher levels of the structure. Three types of control flow are used: sequential, test, and iteration.

Page 2: Structured Programming structured programming: A technique for organizing and coding computer programs in which a hierarchy of modules is used, each having

Advantages of Structured Programming

• Easy to write:Modular design increases the programmer's productivity by allowing them to look at the big picture first and focus on details later.

Several Programmers can work on a single, large program, each working on a different module

Studies show structured programs take less time to write than standard programs.

Procedures written for one program can be reused in other programs requiring the same task. A procedure that can be used in many programs is said to be reusable

Page 3: Structured Programming structured programming: A technique for organizing and coding computer programs in which a hierarchy of modules is used, each having

• Easy to debugSince each procedure is specialized to perform just one task, a procedure can be checked individually. Older unstructured programs consist of a sequence of instructions that are not grouped for specific tasks. The logic of such programs is cluttered with details and therefore difficult to follow.

Easy to UnderstandThe relationship between the procedures shows the modular design of the program.

Meaningful procedure names and clear documentation identify the task performed by each moduleMeaningful variable names help the programmer identify the purpose of each variable.

Easy to ChangeSince a correctly written structured program is self-documenting, it can be easily understood by another programmer.

Page 4: Structured Programming structured programming: A technique for organizing and coding computer programs in which a hierarchy of modules is used, each having

Top Down Design

• Top Down Design is a method of designing something that starts with the complete item then breaks it down into smaller and smaller components. In programming it means breaking a difficult task down (divide and conquer) and solving pieces independently until every step can easily be implemented (successive refinement).

Page 5: Structured Programming structured programming: A technique for organizing and coding computer programs in which a hierarchy of modules is used, each having

Dog House Example

• 1. Floor or Base

• 2. Walls

– 2.1 Back Wall

– 2.1.1 Top section2.1.2 Lower section

–2.2. Left Wall2.3 Right Wall2.4 Front Wall

– 2.4.1 Top section2.4.2 Door section

• 3. Roof

– 3.1 Left Side3.2 Right Side

Page 6: Structured Programming structured programming: A technique for organizing and coding computer programs in which a hierarchy of modules is used, each having

• Prepare all sections as described below then join sections using nails and glue as specified.

• 1. Floor or Base - cut to specified size and smooth edges

• 2. Walls

– 2.1 Back Wall

– 2.1.1 Top section - cut triangular shape2.1.2 Lower section - cut square shape and glue and staple to upper part of wall

–2.2. Left Wall - cut to specified dimensions2.3 Right Wall - cut to specified dimensions2.4 Front Wall

– 2.4.1 Top section - cut triangular piece to specified dimensions2.4.2 Door section - use jigsaw to cut U shape for the door in square shape, staple and glue to top section

• 3. Roof

– 3.1 Left Side - cut to specified dimensions3.2 Right Side - cut to specified dimensions

Page 7: Structured Programming structured programming: A technique for organizing and coding computer programs in which a hierarchy of modules is used, each having
Page 8: Structured Programming structured programming: A technique for organizing and coding computer programs in which a hierarchy of modules is used, each having

Hierarchical systems seem to have a property that something considered as an undivided entity on one level is considered as a composite object on the next lowest level of greater detail: as a result, the natural grain of space or time that is applicable at each level decreases by an order of magnitude when we shift our attention from one level to the next lower one. We understand walls in terms of bricks, bricks in terms of crystals, crystals in terms of molecules, etc.-----E. Dijkstra

Page 9: Structured Programming structured programming: A technique for organizing and coding computer programs in which a hierarchy of modules is used, each having

The Fundamental Principle of Structured Programming is that at all times and under all circumstances, the programmer must keep the program within his intellectual grasp. The well-known methods for achieving this can be briefly summarized as follows: 1) top-down design and construction, 2) limited control structures, and 3) limited scope of data structures.-----Tom Harbron

A study of program structure has revealed that programs can differ tremendously in their intellectual manageability. A number of rules have been discovered, violations of which will either seriously impair or totally destroy the intellectual manageability of the program....I now suggest that we confine ourselves to the design and implementation of intellectually manageable programs.-----E. Dijkstra