You are on page 1of 2

Structured programming can be seen as a subset or subdiscipline of imperative programming, one of

the major programming paradigms. It is most famous for removing or reducing reliance on the GOTO
statement.

Historically, several different structuring techniques or methodologies have been developed for writing
structured programs. The most common are:

1. Edsger Dijkstra's structured programming, where the logic of a program is a structure composed
of similar sub-structures in a limited number of ways. This reduces understanding a program to
understanding each structure on its own, and in relation to that containing it, a useful separation
of concerns.
2. A view derived from Dijkstra's which also advocates splitting programs into sub-sections with a
single point of entry, but is strongly opposed to the concept of a single point of exit.

Low-level structure Programming


At a low level, structured programs are often composed of simple, hierarchical program flow structures.
These are sequence, selection, and repetition:

 "Sequence" refers to an ordered execution of statements.

 In "selection" one of a number of statements is executed depending on the state of the program.
This is usually expressed with keywords such as if..then..else..endif, switch, or case.

 In "repetition" a statement is executed until the program reaches a certain state or operations are
applied to every element of a collection. This is usually expressed with keywords such as while,
repeat, for or do..until. Often it is recommended that each loop should only have one entry
point (and in the original structural programming, also only one exit point), and a few languages
enforce this.

A language is described as "block-structured" when it has a syntax for enclosing structures between
bracketed keywords, such as an if-statement bracketed by if..fi as in ALGOL 68, or a code section
bracketed by BEGIN..END, as in PL/I. However, a language is described as "comb-structured" when it has
a syntax for enclosing structures within an ordered series of keywords. A "comb-structured" language has
multiple structure keywords to define separate sections within a block, analogous to the multiple teeth or
prongs in a comb separating sections of the comb. For example, in Ada, a block is a 4-pronged comb with
keywords DECLARE, BEGIN, EXCEPTION, END, and the if-statement in Ada is a 4-pronged comb with
keywords IF, THEN, ELSE, END IF.

Structured programming is often (but not always) associated with a "top-down" approach to design.

"Structured programming" is programming that links control flow blocks (a function, an if statement's
block, etc.) to the scopes of variables. A variable declared inside such a block is invisible outside it.
This leads to programs written with only the following code structures:
1. Sequence of sequentially executed statements.
2. Conditional execution of statements (i.e., "if" statements).
3. Looping.
4. Structured SubRoutine calls (e.g., 'gosub' but not 'goto').
5. StepwiseRefinement
6. StepwiseRefinement is a relatively old technique of SoftwareDesign that has been successfully
used in a wide range of StructuredProgramming and ModularProgramming environments and
languages. It is the procedural (step-by-step) form of SeparationOfConcerns and has what some
may call a fractal nature.
7. The principle of StepwiseRefinement kind of tries to roll-up YouArentGonnaNeedIt and
KeepItSimple in one and most programmers (at least the GoodProgrammers I've encountered)
tend to use StepwiseRefinement intuitively.
8. The software design is approached as being a series of layers of modules of decreasing
abstraction with call flows typically forming hierarchies through the modules. You start by
identifying the top of the hierarchy (essentially main() or do_stuff()) and then apply TopDown
design to work out the next set of modules that need to be built/written.
9. StepwiseRefinement can (and often is) also applied even down to the function level in languages
such as CeeLanguage.
10. For example, the top level might be the function main(). The SoftwareEngineer decides that main
needs to call func1() and func2(), so she writes the function main() to call func1() and func2() but
leaves func1() and func2() stubbed out with printf's. She then runs her UnitTests and confirms
that func1() and func2() are called correctly i.e. we get printfs coming out where expected, so
main() works. She then implements func1() which is straightforward, and runs the UnitTests once
more to verify that both main() and func1() operate together correctly. She then goes back to look
at func2() but realizes that func2() needs another lower level function, func3() to work. So, she
implements func2() to call func3() but again just leaves func3() stubbed out. Once more the
UnitTests are run to confirm that the software works correctly. The final stage is then to
implement func3() and finished checking the software with the UnitTests.
11. The advantage of StepwiseRefinement is that it allows for IncrementalDevelopment but on a
much finer level of granularity. A little bit like BarryBoehm's SpiralModel. It also uses UnitTests
as an integral feature of the development process. The software is also rapidly built as
StepwiseRefinement lends itself naturally to producing working (and tested) prototypes of the
software as it develops, and it is often possible to build prototypes in remarkably short periods of
time as you can apply YAGNI pretty much down to the function level. StepwiseRefinement is
highly scalable, as large systems can be developed in a structured and predictable fashion from it.
12. The downside is that StepwiseRefinement is open to interpretation of precisely what abstraction
functions are required at the higher levels. This generates a tendency towards an architecture that
has one larger high-level module with several smaller "worker" modules below it. That is, the
hierarchy tends to grow across rather than down (which is the intention).

You might also like