Computer Programming/Structured programming
Overview[edit | edit source]
Structured programming is the suggested antidote to unstructured programming, which existed for decades before Structured programming was invented.
In the beginning, there was UN-structured programming[edit | edit source]
An unstructured program is a procedural program – the statements are executed in sequence as written. But this type of programming uses the goto statement. A goto statement allows control to be passed to any other place in the program. When a goto statement is executed, the sequence continues from the target of the goto. Thus to understand how a program works, you have to pretend to execute it. This means that it is often difficult to understand the logic of such a program. Some program compilers cross-index where a goto connects to, making it practical to rapidly navigate the source code. However, it was a common practice in some programming languages to use a variable in association with where the goto goes, making automated indexing impractical. There are similar problems in some structured programming languages, such as how foreign language views are implemented, to permit many people to view the same computer data, in their human language.
This contrasts with the idea of using some form of abstraction to understand how a program works - as in structured programming.
For this reason, it was suggested by Dijkstra that the goto statement should be banned.
Structured programming[edit | edit source]
In one view, structured programming is programming that avoids using the potentially dangerous goto statement. This prevents potentially confusing transfers of control. Many structured programming languages support the goto statement, which can be used in a structured manner. For example, to exit to the end of a routine, or return to the beginning of a loop.
In another view, structured programming confines itself to using control structures having only one entry point and one exit point. The most important of these structures are sequence, selection (if and if..else) and repetition (while).
Yet another view is that structured programs are programs written in such a way that they can be understood easily using abstraction. Abstraction means being able to understand the overall purpose of some code without understanding the detail. A prime mechanism for abstraction is the procedure (method). But the above-mentioned single-entry single-exit structures also help in using abstraction.
Structured programming was made possible by high-level languages and packages of related programs, that could be flow charted with software diagramming techniques understandable to non-programmers.
The Inventors[edit | edit source]
A few computer scientists were responsible for discovering the idea of Structured Programming, and communicating this notion to the world of other programmers. Structured programming was first embodied in the ALGOL (Algorithmic Language) language (which became the first high-level language used for systems programming in the Burroughs B5000 MCP (OS), (designed by Bob Barton, later a professor at the University of Utah, where he influenced a student Alan Kay who invented the GUI window and was one of the developers of Smalltalk). In turn, ALGOL became the basis of Simula, the first object-oriented language.
ALGOL was based on a language design formalism called BNF (Backus-Naur Form) after its originators John Backus and Peter Naur.
The landmark book in the technique was "Structured Programming" (Academic Press 1972), which contained three sections: "Notes on Structured Programming" by Edsger W. Dijkstra, "Notes on Data Structuring" by C.A.R. Hoare, and "Hierarchical Program Structures" by Ole-Johan Dahl and C.A.R Hoare. The last section introduced Simula and its object-oriented and concurrency features.
Edsgar Djikstra also wrote the book "A Discipline of Programming" (Prentice Hall, 1976).
Another luminary in the structured programming world is Donald Knuth who wrote the multi-volume "The Art of Computer Programming".
Later a book called "Structured Design" was written by Ed Yourdon and Larry Constantine, which many consider is structured programming, but it is not. This was a graphical technique which was extremely tedious in practice, and although mostly abandoned has successors in other non-formal approaches such as UML. The technique outlined in Structured Design and Structured Programming are very different and should not be confused because they share the word Structured.
- Isn't goto evil? - comparing goto and return.