Jump to content

Spaghetti code: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m Reverted edits by 2603:8081:9940:83:4070:CBC5:C5EF:2A3C (talk) to last version by Oleum
m Reverting possible vandalism by 2605:2280:1:FCE9:CC8A:CD3:352C:F30D to version by Pol098. Report False Positive? Thanks, ClueBot NG. (4344418) (Bot)
 
(45 intermediate revisions by 34 users not shown)
Line 1: Line 1:
{{short description|Software source code with poor structure}}
{{short description|Software source code with poor structure}}
'''Spaghetti code''' is a [[pejorative]] phrase for unstructured and difficult-to-[[Software maintenance|maintain]] [[source code]]. Spaghetti code can be caused by several factors, such as volatile [[Software project management|project]] requirements, lack of [[programming style]] rules, and [[software engineer]]s with insufficient ability or experience.<ref name="Markus4">{{cite journal|last1=Markus|first1=Pizka|title=Straightening spaghetti-code with refactoring?|journal=Software Engineering Research and Practice|date=2004|pages=846–852|url=http://itestra.com/wp-content/uploads/2017/08/04_itestra_straightening_spaghetti_code_with_refactoring.pdf|access-date=5 March 2018}}</ref>
'''Spaghetti code''' is a [[pejorative]] phrase for difficult-to-[[Software maintenance|maintain]] and unstructured [[computer]] [[source code]]. Code being developed with poor structure can be due to any of several factors, such as volatile project requirements, lack of [[programming style]] rules, and [[software engineer]]s with insufficient ability or experience.<ref name="Markus4">{{cite journal|last1=Markus|first1=Pizka|title=Straightening spaghetti-code with refactoring?|journal=Software Engineering Research and Practice|date=2004|pages=846–852|url=http://itestra.com/wp-content/uploads/2017/08/04_itestra_straightening_spaghetti_code_with_refactoring.pdf|access-date=5 March 2018|archive-date=5 March 2018|archive-url=https://web.archive.org/web/20180305202716/http://itestra.com/wp-content/uploads/2017/08/04_itestra_straightening_spaghetti_code_with_refactoring.pdf|url-status=dead}}</ref>


== Meaning ==
== Meaning ==
Code that overuses [[Goto|GOTO]] statements rather than [[structured programming]] constructs, resulting in convoluted and unmaintainable programs, is often called spaghetti code.<ref name="Cram5">{{cite journal|last1=Cram|first1=David|last2=Hedley|first2=Paul|title=Pronouns and procedural meaning: The relevance of spaghetti code and paranoid delusion|journal=Oxford University Working Papers in Linguistics, Philology and Phonetics|date=2005|volume=10|pages=187–210|url=http://mostlyharmless.org.uk/wp-content/uploads/2010/12/cramhedley-web.pdf|access-date=5 March 2018}}</ref>
Code that overuses [[Goto|GOTO]] statements rather than [[structured programming]] constructs, resulting in convoluted and unmaintainable programs, is often called spaghetti code.<ref name="Cram5">{{cite journal|last1=Cram|first1=David|last2=Hedley|first2=Paul|title=Pronouns and procedural meaning: The relevance of spaghetti code and paranoid delusion|journal=Oxford University Working Papers in Linguistics, Philology and Phonetics|date=2005|volume=10|pages=187–210|url=http://mostlyharmless.org.uk/wp-content/uploads/2010/12/cramhedley-web.pdf|access-date=5 March 2018|archive-date=6 March 2018|archive-url=https://web.archive.org/web/20180306022905/http://mostlyharmless.org.uk/wp-content/uploads/2010/12/cramhedley-web.pdf|url-status=dead}}</ref>
Such code has a complex and tangled [[control structure]], resulting in a program flow that is conceptually like a [[Spaghetti#Serving|bowl of spaghetti]], twisted and tangled<!-- pages 235–236 -->.<ref>{{cite book|last1=Horstmann|first1=Cay|title=Java Concepts for AP Computer Science|date=2008|publisher=J. Wiley & Sons|location=Hoboken, NJ|isbn=978-0-470-18160-7|pages=235–236|edition=5th ed. [i.e. 2nd ed.].|chapter-url=http://horstmann.com/bigjava3.html|access-date=2 January 2017|language=en|chapter=Chapter 6 - Iteration}}</ref>
Such code has a complex and tangled [[control structure]], resulting in a program flow that is conceptually like a [[Spaghetti#Serving|bowl of spaghetti]], twisted and tangled<!-- pages 235–236 -->.<ref>{{cite book|last1=Horstmann|first1=Cay|title=Java Concepts for AP Computer Science|date=2008|publisher=J. Wiley & Sons|location=Hoboken, NJ|isbn=978-0-470-18160-7|pages=235–236|edition=5th ed. [i.e. 2nd ed.].|chapter-url=http://horstmann.com/bigjava3.html|access-date=2 January 2017|language=en|chapter=Chapter 6 - Iteration}}</ref>

In a 1980 publication by the [[National Institute of Standards and Technology|United States National Bureau of Standards]], the phrase '''spaghetti program''' was used to describe older programs having "fragmented and scattered files".<ref>{{cite book|title=ASTM special technical publication|issue=500–565|author=United States National Bureau of Standards|publisher=United States Government Printing Office|year=1980}}</ref><!-- page 15 -->
In a 1980 publication by the [[National Institute of Standards and Technology|United States National Bureau of Standards]], the phrase '''''spaghetti program''''' was used to describe older programs having "fragmented and scattered files".<ref>{{cite book|title=ASTM special technical publication|issue=500–565|author=United States National Bureau of Standards|publisher=United States Government Printing Office|year=1980}}</ref><!-- page 15 -->
Spaghetti code can also describe an [[anti-pattern]] in which [[Object-oriented programming|object-oriented code]] is written in a procedural style, such as by creating classes whose methods are overly long and messy, or forsaking object oriented concepts like [[Polymorphism (computer science)|polymorphism]].<ref name="Moha10">{{cite journal|last1=Moha|first1=N.|last2=Gueheneuc|first2=Y. G.|last3=Duchien|first3=L.|last4=Meur|first4=A. F. Le|title=DECOR: A Method for the Specification and Detection of Code and Design Smells|journal=IEEE Transactions on Software Engineering|date=January 2010|volume=36|issue=1|pages=20–36|doi=10.1109/TSE.2009.50|issn=0098-5589|citeseerx=10.1.1.156.1524}}</ref> The presence of this form of spaghetti code can significantly reduce the comprehensibility of a system.<ref name="Abbes11">{{cite book|last1=Abbes|first1=M.|last2=Khomh|first2=F.|last3=Gueheneuc|first3=Y. G.|last4=Antoniol|first4=G.|title=An Empirical Study of the Impact of Two Antipatterns, Blob and Spaghetti Code, on Program Comprehension|journal=2011 15th European Conference on Software Maintenance and Reengineering|date=2011|pages=181–190|doi=10.1109/CSMR.2011.24|isbn=978-1-61284-259-2|citeseerx=10.1.1.294.1685}}</ref>

Spaghetti code can also describe an [[anti-pattern]] in which [[Object-oriented programming|object-oriented code]] is written in a procedural style, such as by creating classes whose methods are overly long and messy, or forsaking object-oriented concepts like [[Polymorphism (computer science)|polymorphism]].<ref name="Moha10">{{cite journal|last1=Moha|first1=N.|last2=Gueheneuc|first2=Y. G.|last3=Duchien|first3=L.|last4=Meur|first4=A. F. Le|title=DECOR: A Method for the Specification and Detection of Code and Design Smells|journal=IEEE Transactions on Software Engineering|date=January 2010|volume=36|issue=1|pages=20–36|doi=10.1109/TSE.2009.50|issn=0098-5589|citeseerx=10.1.1.156.1524|s2cid=14767901}}</ref> The presence of this form of spaghetti code can significantly reduce the comprehensibility of a system.<ref name="Abbes11">{{cite book|last1=Abbes|first1=M.|last2=Khomh|first2=F.|last3=Gueheneuc|first3=Y. G.|last4=Antoniol|first4=G.|title=2011 15th European Conference on Software Maintenance and Reengineering |chapter=An Empirical Study of the Impact of Two Antipatterns, Blob and Spaghetti Code, on Program Comprehension |date=2011|pages=181–190|doi=10.1109/CSMR.2011.24|isbn=978-1-61284-259-2|citeseerx=10.1.1.294.1685|s2cid=14152638}}</ref>


== History ==
== History ==
It is not clear when the phrase spaghetti code came into common usage; however, several references appeared in 1977 including ''Macaroni is Better Than Spaghetti'' by Guy Steele.<ref>Guy Lewis Steele. 1977. Macaroni is better than spaghetti. In Proceedings of the 1977 symposium on Artificial intelligence and programming languages. Association for Computing Machinery, New York, NY, USA, 60–66. DOI:https://doi.org/10.1145/800228.806933</ref> In the 1978 book ''A primer on disciplined programming using PL/I, PL/CS, and PL/CT'', Richard Conway used the term to describe types of programs that "have the same clean logical structure as a plate of spaghetti",<ref>{{cite book|title=A primer on disciplined programming using PL/I, PL/CS, and PL/CT|last=Conway|first=Richard|publisher=Winthrop Publishers|year=1978|isbn=978-0-87626-712-7}}</ref><!-- page 186 --> a phrase repeated in the 1979 book ''An Introduction to Programming'' he co-authored with [[David Gries]].<ref>{{cite book|title=An Introduction to Programming|last1=Conway|first1=Richard|last2=Gries|first2=David|edition=3rd|publisher=Little, Brown|year=1979|isbn=978-0-316-15414-7}}</ref><!-- page 158 --> In the 1988 paper ''A spiral model of software development and enhancement'', the term is used to describe the older practice of the ''code and fix model'', which lacked planning and eventually led to the development of the [[waterfall model]].<ref>{{cite journal|journal=IEEE Computer|title=A spiral model of software development and enhancement|last=Boehm|first=Barry W.|volume=21|issue=2|date=May 1988|pages=61–72|doi=10.1109/2.59}}</ref><!-- page 63 --> In the 1979 book ''Structured programming for the COBOL programmer'', author Paul Noll uses the phrases ''spaghetti code'' and ''rat's nest'' as synonyms to describe poorly structured source code.<ref>{{cite book|title=Structured programming for the COBOL programmer: design, documentation, coding, testing|last=Noll|first=Paul|publisher=M. Murach & Associates|year=1977}}</ref><!-- page 15 -->
It is not clear when the phrase spaghetti code came into common usage; however, several references appeared in 1977 including ''Macaroni is Better Than Spaghetti'' by [[Guy L. Steele Jr.|Guy Steele]].<ref>Guy Lewis Steele. 1977. Macaroni is better than spaghetti. In Proceedings of the 1977 symposium on Artificial intelligence and programming languages. Association for Computing Machinery, New York, NY, USA, 60–66. DOI:https://doi.org/10.1145/800228.806933</ref> In the 1978 book ''A primer on disciplined programming using PL/I, PL/CS, and PL/CT'', [[Richard W. Conway|Richard Conway]] described programs that "have the same clean logical structure as a plate of spaghetti",<ref>{{cite book|title=A primer on disciplined programming using PL/I, PL/CS, and PL/CT|last=Conway|first=Richard|publisher=Winthrop Publishers|year=1978|isbn=978-0-87626-712-7}}</ref><!-- page 186 --> a phrase repeated in the 1979 book ''An Introduction to Programming'' he co-authored with [[David Gries]].<ref>{{cite book|title=An Introduction to Programming|last1=Conway|first1=Richard|last2=Gries|first2=David|edition=3rd|publisher=Little, Brown|year=1979|isbn=978-0-316-15414-7}}</ref><!-- page 158 --> In the 1988 paper ''A spiral model of software development and enhancement'', the term is used to describe the older practice of the ''code and fix model'', which lacked planning and eventually led to the development of the [[waterfall model]].<ref>{{cite journal|journal=IEEE Computer|title=A spiral model of software development and enhancement|last=Boehm|first=Barry W.|volume=21|issue=2|date=May 1988|pages=61–72|doi=10.1109/2.59|s2cid=1781829}}</ref><!-- page 63 --> In the 1979 book ''Structured programming for the COBOL programmer'', author Paul Noll uses the phrases ''spaghetti code'' and ''rat's nest'' as synonyms to describe poorly structured source code.<ref>{{cite book|title=Structured programming for the COBOL programmer: design, documentation, coding, testing|last=Noll|first=Paul|publisher=M. Murach & Associates|year=1977}}</ref><!-- page 15 -->


In the ''Ada – Europe '93'' conference, [[Ada (programming language)|Ada]] was described as forcing the programmer to "produce understandable, instead of spaghetti code", because of its restrictive exception propagation mechanism.<ref>{{cite conference|conference=Ada – Europe '93 (Proceedings)|book-title=Lecture Notes in Computer Science|title=Use and abuse of exceptions — 12 guidelines for proper exception handling|last=Schwille|first=Jürgen |volume=688|year=1993|publisher=Springer Berlin Heidelberg|pages=142–152|doi=10.1007/3-540-56802-6_12}}</ref>
In the ''Ada – Europe '93'' conference, [[Ada (programming language)|Ada]] was described as forcing the programmer to "produce understandable, instead of spaghetti code", because of its restrictive exception propagation mechanism.<ref>{{cite conference|conference=Ada – Europe '93 (Proceedings)|book-title=Lecture Notes in Computer Science|title=Use and abuse of exceptions — 12 guidelines for proper exception handling|last=Schwille|first=Jürgen |series=Lecture Notes in Computer Science |volume=688|year=1993|publisher=Springer Berlin Heidelberg|pages=142–152|doi=10.1007/3-540-56802-6_12|isbn=978-3-540-56802-5 }}</ref>


In a 1981 computer languages spoof in ''The Michigan Technic'' titled "BASICally speaking...FORTRAN bytes!!", the author described [[FORTRAN]] stating that "it consists entirely of spaghetti code".<ref>{{cite journal|journal=The Michigan Technic|title=BASICally speaking...FORTRAN bytes!!|author=MTSBS{{clarify|date=April 2015}}|
In a 1981 computer languages spoof in ''The Michigan Technic'' titled "BASICally speaking...FORTRAN bytes!!", the author described [[FORTRAN]] stating that "it consists entirely of spaghetti code".<ref>{{cite journal|journal=The Michigan Technic|title=BASICally speaking...FORTRAN bytes!!|author=MTSBS{{clarify|date=April 2015}}|
volume=99|issue=4|date=March–April 1981}}</ref><!-- page 18 -->
volume=99|issue=4|date=March–April 1981}}</ref><!-- page 18 -->


Richard Hamming described in his lectures<ref>{{cite book |last1=Hamming |first1=Richard |title=The Art of Doing Science and Engineering |date=1996 |isbn=9056995006}}</ref> the etymology of the term in the context of early programming in binary codes:
[[Richard Hamming]] described in his lectures<ref>{{cite book |last1=Hamming |first1=Richard |title=The Art of Doing Science and Engineering |date=1996 |publisher=Taylor & Francis |isbn=9056995006}}</ref> the etymology of the term in the context of early programming in binary codes:


{{Quote
{{Quote
Line 24: Line 26:
== Related phrases ==
== Related phrases ==
===Ravioli code===
===Ravioli code===
[[Ravioli]] code is a term specific to [[object-oriented programming]]. It describes code that comprises well-structured [[Class (computer programming)|classes]] that are easy to understand in isolation, but difficult to understand as a whole.<ref name="Troyer91">{{cite book|last1=Troyer|first1=O. De|title=The OO-binary relationship model : A truly object oriented conceptual model|journal=Advanced Information Systems Engineering|volume=141|date=13 May 1991|pages=561–578|doi=10.1007/3-540-54059-8_104|language=en|series=Notes on Numerical Fluid Mechanics and Multidisciplinary Design|isbn=978-3-319-98176-5}}</ref>
[[Ravioli]] code is a term specific to [[object-oriented programming]]. It describes code that comprises well-structured [[Class (computer programming)|classes]] that are easy to understand in isolation, but difficult to understand as a whole.<ref name="Troyer91">{{cite conference|last1=De Troyer|first1=O.|title=The OO-binary relationship model : A truly object oriented conceptual model|conference=Advanced Information Systems Engineering|volume=498|date=13 May 1991|pages=561–578|doi=10.1007/3-540-54059-8_104|language=en|series=Notes on Numerical Fluid Mechanics and Multidisciplinary Design|isbn=978-3-319-98176-5|s2cid=10894568 |editor-last=Andersen |editor-first=Rudolf|editor2-last=Bubenko |editor2-first=Janis A. |editor3-last=Sølvberg |editor3-first=Arne|url=https://pure.uvt.nl/ws/files/5292185/DTO5613576.pdf}}</ref>


===Lasagna code===
===Lasagna code===
{{Main|Architectural layer|Layer (object-oriented design)}}
{{See also|Architectural layer|Layer (object-oriented design)}}
[[Lasagna]] code refers to code whose layers are so complicated and intertwined that making a change in one layer would necessitate changes in all other layers.<ref name="Latchezar18">{{cite journal|last1=Tomov|first1=Latchezar|last2=Ivanova|first2=Valentina|title=Teaching Good Practices In Software Engineering by Counterexamples|journal=Computer Science and Education in Computer Science|date=October 2014|issue=1|pages=397–405|url=https://www.researchgate.net/publication/301298530|access-date=5 March 2018}}</ref>
[[Lasagna]] code refers to code whose layers are so complicated and intertwined that making a change in one layer would necessitate changes in all other layers.<ref name="Latchezar18">{{cite journal|last1=Tomov|first1=Latchezar|last2=Ivanova|first2=Valentina|title=Teaching Good Practices In Software Engineering by Counterexamples|journal=Computer Science and Education in Computer Science|date=October 2014|issue=1|pages=397–405|url=https://www.researchgate.net/publication/301298530|access-date=5 March 2018}}</ref>


Line 34: Line 36:


<syntaxhighlight lang="basic">
<syntaxhighlight lang="basic">
1 i=0;
1 i=0
2 i=i+1

3 PRINT i;"squared=";i*i
2 i=i+1;
4 IF i>=100 THEN GOTO 6

5 GOTO 2
3 PRINT i; "squared=";i*i;
6 PRINT "Program Completed."

4 IF i>=100 THEN GOTO 6;

5 GOTO 2;

6 PRINT "Program Completed.";

7 END
7 END

</syntaxhighlight>
</syntaxhighlight>


Here is the same code written in a [[structured programming]] style:
Here is the same code written in a [[structured programming]] style:


<syntaxhighlight lang="gwbasic">
<syntaxhighlight lang="basic">
1 FOR i=1 TO 100
1 FOR i=1 TO 100
2 PRINT i;"squared=";i*i
2 PRINT i;"squared=";i*i
Line 63: Line 58:


Here is another example of Spaghetti code with embedded GOTO statements.
Here is another example of Spaghetti code with embedded GOTO statements.
<syntaxhighlight lang="gwbasic">
<syntaxhighlight lang="basic">
INPUT "How many numbers should be sorted? "; T
INPUT "How many numbers should be sorted? "; T
DIM n(T)
DIM n(T)
Line 72: Line 67:
'Calculations:
'Calculations:
C = T
C = T
E180:
E180:
C = INT(C / 2)
C = INT(C / 2)
IF C = 0 THEN GOTO C330
IF C = 0 THEN GOTO C330
D = T - C
D = T - C
E = 1
E = 1
I220:
I220:
f = E
f = E
F230:
F230:
g = f + C
g = f + C
IF n(f) > n(g) THEN SWAP n(f), n(g)
IF n(f) > n(g) THEN SWAP n(f), n(g)
Line 86: Line 81:
E = E + 1
E = E + 1
IF E > D THEN GOTO E180
IF E > D THEN GOTO E180
GOTO I220
GOTO I220
C330:
C330:
PRINT "The sorted list is"
PRINT "The sorted list is"
FOR i = 1 TO T
FOR i = 1 TO T
Line 98: Line 93:
* [[Big ball of mud]], a piece of software with no perceivable architecture
* [[Big ball of mud]], a piece of software with no perceivable architecture
* [[International Obfuscated C Code Contest]], a competition to produce pleasingly obscure C code
* [[International Obfuscated C Code Contest]], a competition to produce pleasingly obscure C code
* [[Technical debt]]
* [[Write-only language]], a language with such bizarre syntax that resulting code is incomprehensible
* ''[[The Elements of Programming Style]]''
*[[Technical debt]]


== References ==
== References ==
Line 106: Line 101:
== External links ==
== External links ==
* [http://portal.acm.org/citation.cfm?id=362929.362947 Go To Statement Considered Harmful]. The classic repudiation of spaghetti code by [[Edsger Dijkstra]]
* [http://portal.acm.org/citation.cfm?id=362929.362947 Go To Statement Considered Harmful]. The classic repudiation of spaghetti code by [[Edsger Dijkstra]]
* [http://www.fortran.com/fortran/come_from.html ''We don't know where to GOTO if we don't know where we've COME FROM'' by R. Lawrence Clark from DATAMATION, December, 1973]
* [http://www.fortran.com/fortran/come_from.html ''We don't know where to GOTO if we don't know where we've COME FROM'' by R. Lawrence Clark from DATAMATION, December, 1973] {{Webarchive|url=https://web.archive.org/web/20180716171336/http://www.fortran.com/fortran/come_from.html |date=2018-07-16 }}
* [http://yost.com/computers/java/java-spaghetti/ Refactoring Java spaghetti code into Java bento code] separating out a bowl full of code from one class into seven classes
* [http://yost.com/computers/java/java-spaghetti/ Refactoring Java spaghetti code into Java bento code] separating out a bowl full of code from one class into seven classes
* [https://archive.is/20130201082958/http://www.remotesynthesis.com/post.cfm/Objects-and-Frameworks--Taking-a-Step-Back Objects and Frameworks – Taking a Step Back] by Brian Rinaldi
* [https://archive.today/20130201082958/http://www.remotesynthesis.com/post.cfm/Objects-and-Frameworks--Taking-a-Step-Back Objects and Frameworks – Taking a Step Back] by Brian Rinaldi
* [https://www.docsity.com/en/news/programming-2/programming-pasta-spaghetti-lasagna-ravioli-macaroni-code/ Programming Pasta - Spaghetti, Lasagna, Ravioli and Macaroni Code]
* [https://blog.docsity.com/en/study-tips/programming-2/programming-pasta-spaghetti-lasagna-ravioli-macaroni-code/ Programming Pasta - Spaghetti, Lasagna, Ravioli and Macaroni Code] {{Webarchive|url=https://web.archive.org/web/20230121050907/https://blog.docsity.com/en/study-tips/programming-2/programming-pasta-spaghetti-lasagna-ravioli-macaroni-code/ |date=2023-01-21 }}
* [http://whatis.techtarget.com/definition/Pasta-Theory-of-Programming Pasta Theory of Programming]
* [https://www.techopedia.com/definition/24994/pasta-theory Pasta Theory of Programming]
* [http://spaghetticodebook.com Spaghetti Code: Detangling Life and Work with Programmer Wisdom (English Edition)]


[[Category:Anti-patterns]]
[[Category:Anti-patterns]]
[[Category:Articles with example BASIC code]]
[[Category:Articles with example BASIC code]]
[[Category:Software engineering folklore]]
[[Category:Software engineering folklore]]
[[Category:Pejorative terms]]
[[Category:Pejorative terms related to technology]]
[[Category:Metaphors referring to spaghetti]]
[[Category:Metaphors referring to spaghetti]]

Latest revision as of 16:14, 11 September 2024

Spaghetti code is a pejorative phrase for difficult-to-maintain and unstructured computer source code. Code being developed with poor structure can be due to any of several factors, such as volatile project requirements, lack of programming style rules, and software engineers with insufficient ability or experience.[1]

Meaning

[edit]

Code that overuses GOTO statements rather than structured programming constructs, resulting in convoluted and unmaintainable programs, is often called spaghetti code.[2] Such code has a complex and tangled control structure, resulting in a program flow that is conceptually like a bowl of spaghetti, twisted and tangled.[3]

In a 1980 publication by the United States National Bureau of Standards, the phrase spaghetti program was used to describe older programs having "fragmented and scattered files".[4]

Spaghetti code can also describe an anti-pattern in which object-oriented code is written in a procedural style, such as by creating classes whose methods are overly long and messy, or forsaking object-oriented concepts like polymorphism.[5] The presence of this form of spaghetti code can significantly reduce the comprehensibility of a system.[6]

History

[edit]

It is not clear when the phrase spaghetti code came into common usage; however, several references appeared in 1977 including Macaroni is Better Than Spaghetti by Guy Steele.[7] In the 1978 book A primer on disciplined programming using PL/I, PL/CS, and PL/CT, Richard Conway described programs that "have the same clean logical structure as a plate of spaghetti",[8] a phrase repeated in the 1979 book An Introduction to Programming he co-authored with David Gries.[9] In the 1988 paper A spiral model of software development and enhancement, the term is used to describe the older practice of the code and fix model, which lacked planning and eventually led to the development of the waterfall model.[10] In the 1979 book Structured programming for the COBOL programmer, author Paul Noll uses the phrases spaghetti code and rat's nest as synonyms to describe poorly structured source code.[11]

In the Ada – Europe '93 conference, Ada was described as forcing the programmer to "produce understandable, instead of spaghetti code", because of its restrictive exception propagation mechanism.[12]

In a 1981 computer languages spoof in The Michigan Technic titled "BASICally speaking...FORTRAN bytes!!", the author described FORTRAN stating that "it consists entirely of spaghetti code".[13]

Richard Hamming described in his lectures[14] the etymology of the term in the context of early programming in binary codes:

If, in fixing up an error, you wanted to insert some omitted instructions then you took the immediately preceding instruction and replaced it by a transfer to some empty space. There you put in the instruction you just wrote over, added the instructions you wanted to insert, and then followed by a transfer back to the main program. Thus the program soon became a sequence of jumps of the control to strange places. When, as almost always happens, there were errors in the corrections you then used the same trick again, using some other available space. As a result the control path of the program through storage soon took on the appearance of a can of spaghetti. Why not simply insert them in the run of instructions? Because then you would have to go over the entire program and change all the addresses which referred to any of the moved instructions! Anything but that!

[edit]

Ravioli code

[edit]

Ravioli code is a term specific to object-oriented programming. It describes code that comprises well-structured classes that are easy to understand in isolation, but difficult to understand as a whole.[15]

Lasagna code

[edit]

Lasagna code refers to code whose layers are so complicated and intertwined that making a change in one layer would necessitate changes in all other layers.[16]

Examples

[edit]

Here follows what would be considered a trivial example of spaghetti code in BASIC. The program prints each of the numbers 1 to 100 to the screen along with its square. Indentation is not used to differentiate the various actions performed by the code, and the program's GOTO statements create a reliance on line numbers. The flow of execution from one area to another is harder to predict. Real-world occurrences of spaghetti code are more complex and can add greatly to a program's maintenance costs.

1 i=0
2 i=i+1
3 PRINT i;"squared=";i*i
4 IF i>=100 THEN GOTO 6
5 GOTO 2
6 PRINT "Program Completed."
7 END

Here is the same code written in a structured programming style:

1 FOR i=1 TO 100
2     PRINT i;"squared=";i*i
3 NEXT i
4 PRINT "Program Completed."
5 END

The program jumps from one area to another, but this jumping is formal and more easily predictable, because for loops and functions provide flow control whereas the goto statement encourages arbitrary flow control. Though this example is small, real world programs are composed of many lines of code and are difficult to maintain when written in a spaghetti code fashion.

Here is another example of Spaghetti code with embedded GOTO statements.

  INPUT "How many numbers should be sorted? "; T
  DIM n(T)
  FOR i = 1 TO T
    PRINT "NUMBER:"; i
    INPUT n(i)
  NEXT i
  'Calculations:
  C = T
E180:
  C = INT(C / 2)
  IF C = 0 THEN GOTO C330
  D = T - C
  E = 1
I220:
  f = E
F230:
  g = f + C
  IF n(f) > n(g) THEN SWAP n(f), n(g)
  f = f - C
  IF f > 0 THEN GOTO F230
  E = E + 1
  IF E > D THEN GOTO E180
  GOTO I220
C330:
  PRINT "The sorted list is"
  FOR i = 1 TO T
    PRINT n(i)
  NEXT i

See also

[edit]

References

[edit]
  1. ^ Markus, Pizka (2004). "Straightening spaghetti-code with refactoring?" (PDF). Software Engineering Research and Practice: 846–852. Archived from the original (PDF) on 5 March 2018. Retrieved 5 March 2018.
  2. ^ Cram, David; Hedley, Paul (2005). "Pronouns and procedural meaning: The relevance of spaghetti code and paranoid delusion" (PDF). Oxford University Working Papers in Linguistics, Philology and Phonetics. 10: 187–210. Archived from the original (PDF) on 6 March 2018. Retrieved 5 March 2018.
  3. ^ Horstmann, Cay (2008). "Chapter 6 - Iteration". Java Concepts for AP Computer Science (5th ed. [i.e. 2nd ed.]. ed.). Hoboken, NJ: J. Wiley & Sons. pp. 235–236. ISBN 978-0-470-18160-7. Retrieved 2 January 2017.
  4. ^ United States National Bureau of Standards (1980). ASTM special technical publication. United States Government Printing Office.
  5. ^ Moha, N.; Gueheneuc, Y. G.; Duchien, L.; Meur, A. F. Le (January 2010). "DECOR: A Method for the Specification and Detection of Code and Design Smells". IEEE Transactions on Software Engineering. 36 (1): 20–36. CiteSeerX 10.1.1.156.1524. doi:10.1109/TSE.2009.50. ISSN 0098-5589. S2CID 14767901.
  6. ^ Abbes, M.; Khomh, F.; Gueheneuc, Y. G.; Antoniol, G. (2011). "An Empirical Study of the Impact of Two Antipatterns, Blob and Spaghetti Code, on Program Comprehension". 2011 15th European Conference on Software Maintenance and Reengineering. pp. 181–190. CiteSeerX 10.1.1.294.1685. doi:10.1109/CSMR.2011.24. ISBN 978-1-61284-259-2. S2CID 14152638.
  7. ^ Guy Lewis Steele. 1977. Macaroni is better than spaghetti. In Proceedings of the 1977 symposium on Artificial intelligence and programming languages. Association for Computing Machinery, New York, NY, USA, 60–66. DOI:https://doi.org/10.1145/800228.806933
  8. ^ Conway, Richard (1978). A primer on disciplined programming using PL/I, PL/CS, and PL/CT. Winthrop Publishers. ISBN 978-0-87626-712-7.
  9. ^ Conway, Richard; Gries, David (1979). An Introduction to Programming (3rd ed.). Little, Brown. ISBN 978-0-316-15414-7.
  10. ^ Boehm, Barry W. (May 1988). "A spiral model of software development and enhancement". IEEE Computer. 21 (2): 61–72. doi:10.1109/2.59. S2CID 1781829.
  11. ^ Noll, Paul (1977). Structured programming for the COBOL programmer: design, documentation, coding, testing. M. Murach & Associates.
  12. ^ Schwille, Jürgen (1993). "Use and abuse of exceptions — 12 guidelines for proper exception handling". Lecture Notes in Computer Science. Ada – Europe '93 (Proceedings). Lecture Notes in Computer Science. Vol. 688. Springer Berlin Heidelberg. pp. 142–152. doi:10.1007/3-540-56802-6_12. ISBN 978-3-540-56802-5.
  13. ^ MTSBS[clarification needed] (March–April 1981). "BASICally speaking...FORTRAN bytes!!". The Michigan Technic. 99 (4).{{cite journal}}: CS1 maint: multiple names: authors list (link) CS1 maint: numeric names: authors list (link)
  14. ^ Hamming, Richard (1996). The Art of Doing Science and Engineering. Taylor & Francis. ISBN 9056995006.
  15. ^ De Troyer, O. (13 May 1991). Andersen, Rudolf; Bubenko, Janis A.; Sølvberg, Arne (eds.). The OO-binary relationship model : A truly object oriented conceptual model (PDF). Advanced Information Systems Engineering. Notes on Numerical Fluid Mechanics and Multidisciplinary Design. Vol. 498. pp. 561–578. doi:10.1007/3-540-54059-8_104. ISBN 978-3-319-98176-5. S2CID 10894568.
  16. ^ Tomov, Latchezar; Ivanova, Valentina (October 2014). "Teaching Good Practices In Software Engineering by Counterexamples". Computer Science and Education in Computer Science (1): 397–405. Retrieved 5 March 2018.
[edit]