Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Structured program theorem
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Implications and refinements == The Böhm–Jacopini proof did not settle the question of whether to adopt [[structured programming]] for software development, partly because the construction was more likely to obscure a program than to improve it. On the contrary, it signalled the beginning of the debate. [[Edsger Dijkstra]]'s famous letter, "'''[[Considered Harmful|Go To Statement Considered Harmful]]'''<!--boldface per WP:R#PLA-->," followed in 1968.<ref>{{cite journal|last=Dijkstra|first=Edsger|author-link=Edsger W. Dijkstra|year=1968|title=Go To Statement Considered Harmful|journal=Communications of the ACM|volume=11|issue=3|pages=147–148|doi=10.1145/362929.362947|s2cid=17469809 |doi-access=free}}</ref> Some academics took a purist approach to the Böhm–Jacopini result and argued that even instructions like <code>break</code> and <code>return</code> from the middle of loops are bad practice as they are not needed in the Böhm–Jacopini proof, and thus they advocated that all loops should have a single exit point. This purist approach is embodied in the [[Pascal (programming language)|Pascal programming language]] (designed in 1968–1969), which up to the mid-1990s was the preferred tool for teaching introductory programming classes in academia.<ref name="roberts">Roberts, E. [1995] "[https://web.archive.org/web/20140725130816/http://cs.stanford.edu/people/eroberts/papers/SIGCSE-1995/LoopExits.pdf Loop Exits and Structured Programming: Reopening the Debate]," ACM SIGCSE Bulletin, (27)1: 268–272.</ref> [[Edward Yourdon]] notes that in the 1970s there was even philosophical opposition to transforming unstructured programs into structured ones by automated means, based on the argument that one needed to think in structured programming fashion from the get go. The pragmatic counterpoint was that such transformations benefited a large body of existing programs.<ref name="Yourdon1979">{{cite book|author=E. N. Yourdon|title=Classics in Software Engineering|year=1979|publisher=Yourdon Press|isbn=978-0-917072-14-7|pages=[https://archive.org/details/classicsinsoftwa00your/page/49 49–50]|url-access=registration|url=https://archive.org/details/classicsinsoftwa00your/page/49}}</ref> Among the first proposals for an automated transformation was a 1971 paper by Edward Ashcroft and [[Zohar Manna]].<ref>{{cite journal|last=Ashcroft|first=Edward|author2=Zohar Manna |year=1971|title=The translation of go to programs to 'while' programs|journal=[[Proceedings of IFIP Congress]]}} The paper, which is difficult to obtain in the original conference proceedings due to their limited distribution, was republished in Yourdon's 1979 book pp. 51-65</ref> The direct application of the Böhm–Jacopini theorem may result in additional local variables being introduced in the structured chart, and may also result in some [[code duplication]].<ref name="WattFindlay2004">{{cite book|author1=David Anthony Watt|author2=William Findlay|title=Programming language design concepts|url=https://archive.org/details/programminglangu00watt_497|url-access=limited|year=2004|publisher=John Wiley & Sons|isbn=978-0-470-85320-7|page=[https://archive.org/details/programminglangu00watt_497/page/n246 228]}}</ref> The latter issue is called the [[loop and a half problem]] in this context.<ref name="LoudenLambert2011">{{cite book|author1=Kenneth C. Louden|author2=Kenneth A. Lambert|title=Programming Languages: Principles and Practices|url=https://archive.org/details/programminglangu00loud_140|url-access=limited|year=2011|publisher=Cengage Learning|isbn=978-1-111-52941-3|pages=[https://archive.org/details/programminglangu00loud_140/page/n426 422]–423|edition=3}}</ref> Pascal is affected by both of these problems and according to empirical studies cited by [[Eric S. Roberts]], student programmers had difficulty formulating correct solutions in Pascal for several simple problems, including writing a function for searching an element in an array. A 1980 study by Henry Shapiro cited by Roberts found that using only the Pascal-provided control structures, the correct solution was given by only 20% of the subjects, while no subject wrote incorrect code for this problem if allowed to write a return from the middle of a loop.<ref name="roberts"/> In 1973, [[S. Rao Kosaraju]] proved that it's possible to avoid adding additional variables in structured programming, as long as arbitrary-depth, multi-level breaks from loops are allowed.<ref name="kozen"/><ref>KOSARAJU, S. RAO. "Analysis of structured programs," Proc. Fifth Annual ACM Syrup. Theory of Computing, (May 1973), 240-252; also {{cite journal | doi = 10.1016/S0022-0000(74)80043-7 | volume=9 | title=Analysis of structured programs | year=1974 | journal=Journal of Computer and System Sciences | pages=232–255 | last1 = Kosaraju | first1 = S. Rao| issue=3 | doi-access= }} cited by {{cite journal | author = [[Donald Knuth]] | title = Structured Programming with go to Statements | journal = Computing Surveys | volume = 6 | issue = 4 | year = 1974 | pages = 261–301 | doi = 10.1145/356635.356640 | citeseerx = 10.1.1.103.6084 | s2cid = 207630080 }}</ref> Furthermore, Kosaraju proved that a strict hierarchy of programs exists, nowadays called the ''Kosaraju hierarchy'', in that for every integer ''n'', there exists a program containing a multi-level break of depth ''n'' that cannot be rewritten as program with multi-level breaks of depth less than ''n'' (without introducing additional variables).<ref name="kozen"/> Kosaraju cites the multi-level break construct to the [[BLISS]] programming language. The multi-level breaks, in the form a <code>leave ''label''</code> keyword were actually introduced in the BLISS-11 version of that language; the original BLISS only had single-level breaks. The BLISS family of languages didn't provide an unrestricted goto. The [[Java (programming language)|Java programming language]] would later follow this approach as well.<ref>{{cite journal | doi = 10.1002/spe.470 | title=The BLISS programming language: a history | journal=Software: Practice and Experience | date=2002 | volume=32 | issue=10 | pages=955–981 | first=Ronald F. | last=Brender | s2cid=45466625 | url = https://www.cs.tufts.edu/~nr/cs257/archive/ronald-brender/bliss.pdf}}</ref>{{rp|960–965}} A simpler result from Kosaraju's paper is that a program is reducible to a structured program (without adding variables) if and only if it does not contain a loop with two distinct exits. Reducibility was defined by Kosaraju, loosely speaking, as computing the same function and using the same "primitive actions" and predicates as the original program, but possibly using different control flow structures. (This is a narrower notion of reducibility than what Böhm–Jacopini used.) Inspired by this result, in section VI of his highly-cited paper that introduced the notion of [[cyclomatic complexity]], Thomas J. McCabe described an analogue of [[Kuratowski's theorem]] for the [[control-flow graph]]s (CFG) of non-structured programs, which is to say, the minimal [[Induced subgraph|subgraphs]] that make the CFG of a program non-structured. These subgraphs have a very good description in natural language. They are: # branching out of a loop (other than from the loop cycle test) # branching into a loop # branching into a decision (i.e. into an if "branch") # branching out of a decision McCabe actually found that these four graphs are not independent when appearing as subgraphs, meaning that a necessary and sufficient condition for a program to be non-structured is for its CFG to have as subgraph one of any subset of three of these four graphs. He also found that if a non-structured program contains one of these four sub-graphs, it must contain another distinct one from the set of four. This latter result helps explain how the control flow of non-structured program becomes entangled in what is popularly called "[[spaghetti code]]". McCabe also devised a numerical measure that, given an arbitrary program, quantifies how far off it is from the ideal of being a structured program; McCabe called his measure [[essential complexity (numerical measure of "structuredness")|essential complexity]].<ref name="McCabe">The original paper is {{cite journal |author=Thomas J. McCabe |date=December 1976 |journal=IEEE Transactions on Software Engineering |issue=4 |pages=315–318 |title=A Complexity Measure|url=https://books.google.com/books?id=vtNWAAAAMAAJ&pg=PA3 |doi=10.1109/tse.1976.233837 |volume=SE-2|s2cid=9116234 }} For a secondary exposition see {{cite book|author=Paul C. Jorgensen|title=Software Testing: A Craftsman's Approach, Second Edition|url=https://books.google.com/books?id=Yph_AwAAQBAJ&pg=PA150|year=2002|publisher=CRC Press|isbn=978-0-8493-0809-3|pages=150–153|edition=2nd}}</ref> McCabe's characterization of the [[forbidden graph]]s for structured programming can be considered incomplete, at least if the Dijkstra's D structures are considered the building blocks.<ref>{{cite journal | doi = 10.1093/comjnl/26.3.270 | title=Flowchart Schemata and the Problem of Nomenclature | journal=The Computer Journal | date=1983 | volume=26 | issue=3 | pages=270–276 | first=M. H. | last=Williams| doi-access=free }}</ref>{{rp|274–275}}{{clarify|date=July 2014}} Up to 1990 there were quite a few proposed methods for eliminating gotos from existing programs, while preserving most of their structure. The various approaches to this problem also proposed several notions of equivalence, which are stricter than simply Turing equivalence, in order to avoid output like the folk theorem discussed above. The strictness of the chosen notion of equivalence dictates the minimal set of control flow structures needed. The 1988 [[JACM]] paper by Lyle Ramshaw surveys the field up to that point, as well proposing its own method.<ref>{{Cite journal | doi = 10.1145/48014.48021| title = Eliminating go to's while preserving program structure| journal = Journal of the ACM| volume = 35| issue = 4| pages = 893–920| year = 1988| last1 = Ramshaw | first1 = L. | s2cid = 31001665| doi-access = free}}</ref> Ramshaw's algorithm was used for example in some Java [[decompiler]]s because the [[Java virtual machine]] code has branch instructions with targets expressed as offsets, but the high-level Java language only has multi-level <code>break</code> and <code>continue</code> statements.<ref name="Nolan2004">{{cite book|author=Godfrey Nolan|title=Decompiling Java|year=2004|publisher=Apress|isbn=978-1-4302-0739-9|page=142}}</ref><ref>{{Cite web | url=https://www.usenix.org/legacy/publications/library/proceedings/coots97/full_papers/proebsting2/proebsting2.pdf | title=Krakatoa: Decompilation in Java | website=www.usenix.org}}</ref><ref>{{Cite web | url=http://www.openjit.org/publications/pro1999-06/decompiler-pro-199906.pdf | title=An Effective Decompilation Algorithm for Java Bytecodes | website=www.openjit.org}}</ref> Ammarguellat (1992) proposed a transformation method that goes back to enforcing single-exit.<ref name="amma92">{{cite journal | doi = 10.1109/32.126773 | title=A control-flow normalization algorithm and its complexity | journal=IEEE Transactions on Software Engineering | date=1992 | volume=18 | issue=3 | pages=237–251 | first=Z. | last=Ammarguellat}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)