5

Does the structured programming definition only consider imperative programming? By this I mean does the definition of structured programming automatically exclude functional programming (in the most common usage, by which I mean not necessarily pure-functional programming, but something like Clojure).

Structured programming, at least from the definitions that I've found seem to really be saying: "good programming shouldn't use goto, and should be modular". Which doesn't necessarily exclude functional programming, while most definitions seem to begin with "... is a subset of imperative programming".

I'm looking for a bit of clarification I think.

BTW, I have read "What's The Difference Between Imperative, Procedural and Structured Programming?" which is a pretty good historical description.

9

Suppose that you use and create only pure functions. These by definition have no shared state and are easy to compose, and there's no way to use a goto. This satisfies both 'modularity' and 'structured control flow' properties.

What could it be? A map-reduce calculation. A Prolog inference. An SQL query (can be reused as a subquery or a view). Are you comfortable to put all these under the umbrella of the notion from 1960s?

To me, 'structured programming' is mostly a historical concept, connected to, for instance, 'Goto Considered Harmful' and other works of Dijkstra. It is deeply rooted in imperative world. You do structured programming when you write good C code. You do something different when you write highly modular, well-structured code in Haskell or probably even Scala.

  • Structured programming was introduced when almost all commercial programming was done in either FORTRAN, COBOL, or assembly language. Early programs were necessarily short because memory was limited. In FORTRAN and assembly language the only control constructs were 'IF' and 'GOTO'. Code was written from flow charts that were often quite tangled. As programs grew larger, it was common to have bugs due to reaching some point of the program in an unexpected state. "Structured Programming" was the solution. – kevin cline Mar 17 '18 at 20:13
  • @kevincline: Indeed! I remember writing code in Fortran IV for PDP-11 with 64 to 128 kilobytes of RAM, of which the OS would allocate you a part. It's much like modern small micro-controllers. A flow chart could indeed be an adequate representation of such a small computation. It was badly inadequate when you wanted to describe an air traffic control system, or a ticket reservation system. Hence Algol (look at the features of Algol-68, the spiritual predecessor of C++). – 9000 Mar 18 '18 at 19:22
5

Structured programming is essentially programming by composing procedures.

Can you do something similar with functions in a functional language? Yes.

When people talk about structured programming, do they usually mean to include functional programming? No.

If you say "structured programming style," will people understand you to be including functional programming? No.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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