Question

According to What Wikipedia says about Structured Programming Paradigm

The following qualifies a language to be called Structured

  1. "Sequence"; ordered statements or subroutines executed in sequence.
  2. "Selection"; one or 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.
  3. "Iteration"; a statement or block is executed until the program reaches a certain state, or operations have been applied to every element of a collection. This is usually expressed with keywords such as while, repeat, for or do..until.
  4. Subroutines; callable units such as procedures, functions, methods, or subprograms are used to allow a sequence to be referred to by a single statement.
  5. Blocks are used to enable groups of statements to be treated as if they were one statement.

Must all of these conditions be present or some of it.

If it is some of the rules. Does that mean the unstructured BASIC code below qualifies to be called Structured because it has if/then?

5 LET S = 0
10 MAT INPUT V 
20 LET N = NUM 
30 IF N = 0 THEN 99 
40 FOR I = 1 TO N 
45 LET S = S + V(I) 
50 NEXT I 
60 PRINT S/N 
70 GO TO 5 
99 END

If it must contain all the rule, can we say functional programming is not structured because it has no support for Iteration/looping?


and by the way, i made this flowchart to better understand programming paradigms, is it correct?

Programming Paradigm Chart


Edit After Answer.

After going through Christophe answer.

the diagram below reflect his correction

enter image description here

.........///////////////////////////////..................................

enter image description here

Was it helpful?

Solution

No, the traditional BASIC used in your example is not considered as a structured language:

  • First you cannot call a subroutine with a simple statement, since parameter passing would require to use global variables and additional statements;
  • GOTO allows highly unstructured spaghetti code. Whatever the theory will tell you. GOTO breaks the sequence (a numbered line cannot be sure that the previous line was executed, since a direct GOTO could have lead there), GOTO does allow selection or iteration only in combination with other statements.
  • Finally the language is flat: it does not allowed clear blocks of codes to be defined. Blocs are a group of statements that can be replaced by another block of any size. BASIC's line numbering does not allow this.

FORTRAN was not structured in the beginning, but somewhere (1966?) added block structures and later even selection (1990). But a lot of code is not structured.

So a structured language should at least provide:

  • blocks (without line numbers that could break the flow of control anywhere: you enter and leave a block through clear ways)
  • variables that are local to a block to ensure modularity,
  • clean subroutines with parameter passing,
  • control flow statement that would allow to write a programme without GOTO (even if this statement was included in the language for convenience).

The earliest structured languages were Algol and Pascal. Simula was object oriented but had all the properties of structured programming.

I'm not a language theorist, but I think that your categorization graph is not correct:

  • Non-strutured languages can be imperative
  • OOP is orthogonal : for example, nothing would prevent a functional language to also be object oriented if functions would be considered as a special kind of objects.
  • I'm not sure that declarative languages are necessarily structured. Because declarative languages and functional programming languages try to avoid to define the control flow. So looping, selection, and blocks are not used there for their structural purpose.

OTHER TIPS

I think you can take the term literally. It is important to note there are no structured and unstructured languages, just structured and non-structured pieces of code.

A structure is a building made up out of building blocks. A block can be a sequence of operations or a switch. A switch redirects the code path, transfers execution to the start of a(nother) block.

The point is you have common block types that are easy to understand and language independent. And you should be able to draw the program flow graphically.

When I was in school we had to draw so called Nassi-Shneiderman diagrams to express a solution before we were allowed to write any code because that forced us to create structured code. Whatever you draw is inherently structured, typing in the code once you have the diagram is trivial.

Although NS diagrams never got popular outside academic settings and I never used them after school, I still think they are excellent demonstrators of structured programming.

Licensed under: CC-BY-SA with attribution
scroll top