Structured program theorem

From Wikipedia, the free encyclopedia

The structured program theorem is a result in programming language theory. It states that every computable function can be implemented in a programming language that combines subprograms in only three specific ways. These three control structures are

  1. Executing one subprogram, and then another subprogram (sequence)
  2. Executing one of two subprograms according to the value of a boolean variable (selection)
  3. Executing a subprogram until a boolean variable is true (iteration)

Computer scientists usually credit the theorem to a 1966 paper by Corrado Böhm and Giuseppe Jacopini. However, David Harel traced its origins to the 1946 description of the von Neumann architecture and Stephen Kleene's normal form theorem.

The Böhm-Jacopini proof describes how to construct a structured flow chart from an arbitrary chart, using the bits in an extra integer variable to keep track of information that the original program represents by the program location. This construction was based on Böhm's programming language P′′. The Böhm-Jacopini proof did not settle the question of whether to adopt structured programming for software development, partly because the construction was more likely to obscure a program than to improve it. On the contrary, it signalled the beginning of the debate. Edsger Dijkstra's notorious letter, "Go To Statement Considered Harmful," followed in 1968. Subsequent proofs of the theorem addressed practical shortcomings of the Böhm-Jacopini proof with constructions that maintained or improved the clarity of the original program. [1]

In the 1980s IBM researcher Harlan Mills oversaw the development of the COBOL Structuring Facility, which applied a structuring algorithm to COBOL code. Mills's transformation involved the following steps for each procedure.

  1. Identify the basic blocks in the procedure.
  2. Assign a unique label to each block's entry path, and label each block's exit paths with the labels of the entry paths they connect to. Use 0 for return from the procedure and 1 for the procedure's entry path.
  3. Break the procedure into its basic blocks.
  4. For each block that is the destination of only one exit path, reconnect that block to that exit path.
  5. Declare a new variable in the procedure (called L for reference).
  6. On each remaining unconnected exit path, add a statement that sets L to the label value on that path.
  7. Combine the resulting programs into a selection statement that executes the program with the entry path label indicated by L
  8. Construct a loop that executes this selection statement as long as L is not 0.
  9. Construct a sequence that initializes L to 1 and executes the loop.

Note that this construction can be improved by converting some cases of the selection statement into subprocedures.

[edit] See also

[edit] References

  • Ashcroft, Edward; and Zohar Manna (1971). "The translation of go to programs to 'while' programs". Proceedings of IFIP Congress. 
  • Bohm, Corrado; and Giuseppe Jacopini (May 1966). "Flow Diagrams, Turing Machines and Languages with Only Two Formation Rules". Communications of the ACM 9 (5). 
  • Harel, David (1980). "On Folk Theorems". Communications of the ACM 23: 379. doi:10.1145/358886.358892. 
  • Dijkstra, Edsger (1968). "Go To Statement Considered Harmful". Communications of the ACM 3 http://www.acm.org/classics/oct95/.