====================================================================== = Big ball of mud = ====================================================================== Introduction ====================================================================== Spaghetti code is computer source code that encodes control flow that is convoluted, and therefore, hard to understand. Control statements direct program execution in ways that instead of having a quality of structure, resembles cooked spaghetti, twisted and tangled. The code tends to be hard to maintain. Since control flow logic encoded via the goto statement tends to lead to convoluted control flow, use of goto is often associated with a classification as spaghetti code. The practice of structured programming was envisioned to eliminate the need for and use of the goto statement as one way to avoid the production of spaghetti code. Ensuring the creation of high-quality software, instead of spaghetti code, often involves aspects such as using better tools, training developers and improving software development processes. 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. The presence of this form of spaghetti code can significantly reduce the comprehensibility of a system. History ====================================================================== It is unclear when the phrase 'spaghetti code' was coined; however, a reference appeared in 1972: "The principal motivation behind eliminating the goto statement is the hope that the resulting programs will not look like a bowl of spaghetti." by Martin Hopkins. 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", a phrase repeated in the 1979 book 'An Introduction to Programming' he co-authored with David Gries. 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. 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. 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. 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". 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". Richard Hamming described in his lectures the etymology of the term in the context of early programming in binary codes: Simple ======== The following BASIC code, a program that prints 1 to 100, is a relatively simple example of code that can be more easily understood with structured control flow instead of using goto. The use of for looping and lack of indentation leads to less than clear logic flow. 1 i=0 2 i=i+1 3 PRINT i 4 IF i>=100 THEN GOTO 6 5 GOTO 2 6 END The following code produces the same result, but uses a structured loop statement and indentation to improve readability. 1 FOR i=1 TO 100 2 PRINT i 3 NEXT i 4 END More representative ===================== The following code implements a numeric sorting algorithm. The use of goto statements results in a spaghetti-like nature to the control flow. 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 Big ball of mud{{anchor |big-ball-o-mud}} =========================================== A big ball of mud is a software system that lacks a perceivable architecture. Although undesirable from a software engineering point of view, such systems are common in practice due to business pressures, developer turnover and software entropy. The term was popularized by Brian Foote and Joseph Yoder although they credit Brian Marick for coining the term. Pasta-related =============== Inspired by the popularity of 'spaghetti code', other pasta-oriented terms that describe the structural nature of code include: ; Lasagna code: Lasagna code has layers that are so intertwined that making a change in one layer necessitates changing other layers too. ; Ravioli code: Ravioli code comprises well-structured classes that are easy to understand in isolation but in combination result in less than clear system design. See also ====================================================================== * ' * * 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://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://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.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://blog.docsity.com/en/study-tips/programming-2/programming-pasta-spaghetti-lasagna-ravioli-macaroni-code/ Programming Pasta - Spaghetti, Lasagna, Ravioli and Macaroni Code] * [https://www.techopedia.com/definition/24994/pasta-theory Pasta Theory of Programming] License ========= All content on Gopherpedia comes from Wikipedia, and is licensed under CC-BY-SA License URL: http://creativecommons.org/licenses/by-sa/3.0/ Original Article: http://en.wikipedia.org/wiki/Big_ball_of_mud .