2

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

4
  • 70 GO TO 5 all screws it over the if/then. Nov 28, 2019 at 19:23
  • i do not understand your message
    – LekeOpe
    Nov 28, 2019 at 19:24
  • 1
    That you can still write unstructured code with expressions like the menioned one doesn't make a whole language being categorized as unstructured. Probably I don't fully understand clearly what you're asking about here. Nov 28, 2019 at 19:27
  • 1
    Code that uses named labels and goto's is unstructured; code that uses block nesting is structured. FP has recursion, which is an immutable substitution for iteration.
    – Erik Eidt
    Nov 28, 2019 at 19:52

2 Answers 2

4

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.
3
  • 1
    thanks for detailed answer. Just a little addition: it seems the latest version of BASIC is now structured
    – LekeOpe
    Nov 29, 2019 at 13:38
  • 1
    There are several dialects of BASIC. Some of them are structured, some of them are not. Nov 30, 2019 at 1:15
  • Yes, fair point: now there are also some BASIC dialects that are structured. It’s a similar evolution as described for FORTRAN, but there’s no standard committee to harmonize. But not the dialect shown in the question, because line numbers allow to break the structure. (And in the example the line numbers are used for this purpose in two GOTO). I’d also say that some dialects, like VisualBasic have not much on common with the BASIC dialects I learned in the 80’s or the original Dartmouth one from 1964 ;-) I’ve edited to be more precise.
    – Christophe
    Nov 30, 2019 at 8:32
3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.