Encyclopedia > Structured programming

  Article Content

Structured programming

Structured programming can be seen as a subset or subdiscipline of procedural programming, one of the major paradigms (and probably the most popular one) for programming computers.

Historically, several different structuring techniques have been developed for writing structured programs. The two commonest are Jackson Structured Programming, which is based on aligning data structures with program structures and Dijkstra's structured programming, which is based on splitting programs into sub-sections, each with a single point of entry and of exit. Most people mean the latter when they use the term structured programming and that is what this article will discuss.

It is possible to do structured programming in almost any procedural programming language, but since about 1970 when structured programming began to gain popularity as a technique, most new procedural programming languages have included features to encourage structured programming, (and sometimes have left out features that would make unstructured programming easy). Some of the better known structured programming languages are

At the level of relatively small pieces of code, structured programming typically recommends simple, hierarchical program flow structures. These can be obtained in most modern languages by using only structured looping constructs, often named "while", "repeat", "for". Often it is recommended that each loop should only have one entry point and one exit point, and a few languages enforce this.

Alternative thinking on structured loops exists. Donald Knuth has advocated flow graphs that can be written with all forward branches drawn to the left of the code, all backward branches drawn to the right, and no branches crossing each other in this representation. Those knowledgeable in compilers and graph theory have advocated allowing only reduceable flow graphs.

Coders should break larger pieces of code into shorter subroutines (functions and procedures in some languages) that are small enough to be understood easily. In general, programs should use global variables sparingly; instead, subroutines should use local variables and take arguments by either value or reference. These techniques help to make isolated small pieces of code easier to understand without having to understand the whole program at once.

Structured programming is often (but not always) associated with a "top-down" approach to design[?]. In this way designers map out the large scale structure of a program in terms of smaller operations, implement and test the smaller operations, and then tie them together into a whole program.

By the end of the 20th century, the majority of professional programmers endorsed structured procedural programming. Some claim that colleagues can understand a structured program more easily, leading to improved reliability and easier maintenance. Attempts to actually measure this have been rare, and there is a suspicion in some circles that the benefits are real but small.

Towards the end of the 20th century, designers have created new paradigms loosely based on procedural programming that accept the lessons of structured programming but attempt to go beyond this in providing structure for data as well as for program flow. Object-oriented programming in most cases can be seen as an example of this, although there are also some object-oriented variants that are not procedural.

Unstructured languages define control flow largely in terms of a GOTO command that transfers execution to a label in code. Structured programming languages provide constructs (often called "if-then-else", "unless", "while", "until", and "for") for creating a variety of loops and conditional branches of execution, although they may also provide a GOTO to reduce excessive nesting of cascades of "if" structures, especially for handling exceptional conditions.

Strictly speaking, in a structured programming language, any code structure should have only one entry point and one point of exit; many languages such as C allow multiple paths to a structure's exit (such as "continue", "break", and "return"), which can bring advantages in readability.



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
Holtsville, New York

... York - Wikipedia <<Up     Contents Holtsville, New York Holtsville is a town located in Suffolk County, New York. As of the 2000 census, the ...

 
 
 
This page was created in 55.7 ms