Website development and design blog, tutorials and inspiration

Structured Programming Languages

History and Evolution of Structured Programming Languages

By , 26th May 2010 in Software Engineering

Structured Programming Languages come in all flavours, each with their own style and layout, from BASIC to C#. A structured programming language follows a methodology where the logic of a program is composed of simpler sub-structures, like building blocks.

This methodology is commonly called Dijkstra's structured programming. Edsger Wybe Dijkstra (1930 - 2002) was a Dutch computer scientist. He is known for his low opinion of the GOTO statement and wrote a paper in 1965, which is regarded as a major step towards the widespread depreciation of the GOTO statement. He also famed for coining the programming phrase "2 or more, use a for", alluding to the fact that when you find yourself processing more than one instance of a data structure, it is time to encapsulate that logic inside a loop.

Structured programming is often, but not always, associated with a top-down approach to design where an overview of the system is first formulated, specifying but not detailing any first-level subsystems. Each subsystem is then refined in yet greater detail until the entire specification is reduced to base elements. This idea is the basis for structured design methodologies such as SSADM and UML.

Structured programming usually involves a procedural language, rather that a linear language such as BASIC, although any programming language can be structured.

The first example of first generation BASIC illustrates linear style programming, where the program executes instructions from the top to the bottom. This can be considered as structured as the flow of control does not break out of the linear path.

  1. 10 INPUT "What is your name: ", U$
  2. 20 PRINT "Hello "; U$
  3. 30 INPUT "How many stars do you want: ", N
  4. 40 S$ = ""
  5. 50 FOR I = 1 TO N
  6. 60 S$ = S$ + "*"
  7. 70 NEXT I
  8. 80 PRINT S$
  9. 90 INPUT "Do you want more stars? ", A$
  10. 100 IF LEN(A$) = 0 THEN 90
  11. 110 A$ = LEFT$(A$, 1)
  12. 120 IF A$ = "Y" OR A$ = "y" THEN 30
  13. 130 PRINT "Goodbye ";
  14. 140 FOR I = 1 TO 200
  15. 150 PRINT U$; " ";
  16. 160 NEXT I
  17. 170 PRINT
  18. 180 END

The next example of BASIC illustrates a non-structured program, commonly called spaghetti code. In this example it is easy to see what the code is doing, however, a large program of hundreds of lines would be almost impossible to debug.

  1. 10 GOTO 40
  2. 20 PRINT "line number 20"
  3. 30 GOTO 60
  4. 40 PRINT "line number 40"
  5. 50 GOTO 20
  6. 60 END

This code executes statements in a seemingly random order. It does not appear to execute code in a linear fashion. The result of this code would be:

line number 40
line number 20

It is also possible while using the goto statement to skip over lines of code so that they are never executed:

  1. Print "An example of a GOTO statement"
  2. Sleep 1000
  3. Goto program_continue
  4. Print "This line of code will never be executed"
  6. program_continue:
  7. Print "We just skipped some code"
  8. Sleep
  9. End

For these reasons the goto statement is frowned upon and is not permitted within structured programming languages. Procedures (subs, functions, methods and so on...) are permitted as they still retain a linear flow of control.

In the next example, a sub procedure the program executes in a linear order but jumps down to the procedure when the line is invoked. After the procedure has completed, again in a linear fashion, the flow returns to the same line it jumped out of and continues to the end of the code. This is known as procedural programming.

  1. Print "This Program reads all lines of code"
  2. Gosub program_continue
  3. Print "This line isn't left out"
  4. Sleep
  5. End
  7. program_continue:
  8. Print "We like programs that talk to us!"
  9. Return

Another requirement of a structured programming language is the use of block statements. A language is described as "block-structured" when it has syntax for enclosing structures between bracketed keywords. For example in Pascal, blocks of code are contained within BEGIN and END statements:

  1. for i := 0 to 10 do
  2. begin
  4. end;

and C uses curly brackets (braces) to denote blocks of code:

  1. for (i=0; i<=10; i++)
  2. {
  4. }

Another type of block structure is the comb. These have more than two keywords to denote block structure, for example, the ADA language uses IF, THEN, ELSE, END IF as separate "teeth" on the comb.

  1. if <em>condition</em> then
  2. -- statements;
  3. elseif condition then
  4. -- more statements;
  5. elseif condition then
  6. -- more statements;
  7. else condition then
  8. -- other statements;
  9. end if;

As you gain experience you may find it easier to understand certain violations of the strictly structured programming idea, and several programming languages in widespread use provide restricted jump statements and exception handling for use in these situations. The major industry languages, with the major exception of Java, also retain the GOTO statement within a procedure, and it remains widely used.

Although Dijkstra succeeded in making structured programming the educational standard, he did not succeed in making it a strict requirement.


There are no comments for this post. Be the first!

Leave a Reply

Your email address will not be published.