Spaghetti code

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

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

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!

Ravioli code

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

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

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

References

  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.

Read other articles:

County road in New Jersey, U.S. View facing south from Columbia Terrace in Weehawken. Much of the overlook is lined with trap rock quarried from the cliffs. Boulevard East (officially John F. Kennedy Boulevard East, and sometimes referred to as JFK Boulevard East) is a two-way, mostly two lane, scenic[1][2] county road[3] in the North Hudson, New Jersey municipalities of Weehawken, West New York, Guttenberg and North Bergen. Apart from small sections at either end, the...

У Вікіпедії є статті про інших людей із таким прізвищем: Сєдих. Сєдих Юрій Георгійовичрос. Юрий Георгиевич Седых Загальна інформаціяГромадянство  СРСР→ ФранціяМісце проживання НовочеркаськНародження 11 червня 1955(1955-06-11)[1][2][3]Новочеркаськ, Ростовська о...

  لمعانٍ أخرى، طالع ماستودون (توضيح). اضغط هنا للاطلاع على كيفية قراءة التصنيف مستودون المرتبة التصنيفية جنس  التصنيف العلمي  فوق النطاق  حيويات مملكة عليا  حقيقيات النوى مملكة  حيوان عويلم  ثنائيات التناظر مملكة فرعية  ثانويات الفم شعبة  حبليات شعي

Nguyễn Xuân PhúcNguyễn Xuân Phúc pada tahun 2022Presiden Vietnam ke-10Masa jabatan5 April 2021 – 18 Januari 2023Perdana MenteriPhạm Minh ChínhWakil PresidenVõ Thị Ánh XuânPendahuluNguyễn Phú TrọngPenggantiVõ Thị Ánh Xuân (pelaksana tugas)Perdana Menteri Vietnam ke-8Masa jabatan7 April 2016 – 5 April 2021PresidenTrần Đại QuangĐặng Thị Ngọc Thịnh (Penjabat)Nguyễn Phú TrọngWakilVương Đình HuệPendahuluNguyễn Tấn DũngPen...

Heinrich XXIX, Count of Reuss-EbersdorfBorn(1699-07-21)21 July 1699EbersdorfDied22 May 1747(1747-05-22) (aged 47)HerrnhaagNoble familyHouse of ReussSpouse(s)Sophie Theodora of Castell-RemlingenFatherHeinrich X, Count of Reuss-EbersdorfMotherErdmuthe Benigna of Solms-Laubach Heinrich XXIX, Count of Reuss-Ebersdorf (born 21 July 1699 in Ebersdorf; died: 22 May 1747 in Herrnhaag) was a member of the House of Reuss Younger Line and Count Ebersdorf from 1711 until his death Life Heinrich was ...

  لمعانٍ أخرى، طالع الشعيب (توضيح). الشعيب (محلة) تقسيم إداري البلد  اليمن المحافظة محافظة إب المديرية مديرية المخادر العزلة عزلة السحول القرية قرية الزريبة السكان التعداد السكاني 2004 السكان 36   • الذكور 17   • الإناث 19   • عدد الأسر 4   • عدد المساكن 7 معلومات أ

This article contains content that is written like an advertisement. Please help improve it by removing promotional content and inappropriate external links, and by adding encyclopedic content written from a neutral point of view. (February 2022) (Learn how and when to remove this template message) American investment manager of investment products and strategies The Dreyfus CorporationTypeSubsidiaryFounded1951; New York, NYHeadquartersMetLife Building, New York, NY, USAKey peopleJ. Charles C...

Amira OthmanLahirNadia Amira binti Othman26 Oktober 1993 (umur 30)Skudai, Johor, MalaysiaPendidikanSarjana MusikAlmamaterUniversiti Teknologi MARA (UiTM)PekerjaanPenyanyi, pembawa acara, aktrisTahun aktif2013–kiniKarier musikGenrePop, R&BInstrumenVokalLabelFMC MusicSeventeen Eleven Music (2016-20)Rocketfuel Entertainment (2020-kini)Artis terkaitRaqib Nadia Amira Othman (lahir 26 Oktober 1993) adalah penyanyi, pembawa acara televisi dan aktris Malaysia. Dia adalah mantan murid ...

Esta página cita fontes, mas que não cobrem todo o conteúdo. Ajude a inserir referências. Conteúdo não verificável pode ser removido.—Encontre fontes: ABW  • CAPES  • Google (N • L • A) (Janeiro de 2022) Santa MariaGeografiaPaís  PortugalRegião autónoma AçoresLocalização geográfica AçoresParte de AçoresSede Vila do PortoBanhado por Oceano AtlânticoÁrea 97,18 km2Ponto culminante Pico Alto (Vila do Porto)Coor...

Medication used to treat malaria and babesiosis Not to be confused with quinidine, quinone, quinoline, or chloroquine. For the Nine album, see Quinine (album). For the flowering herb known as wild quinine, see Parthenium integrifolium. QuinineClinical dataPronunciationUS: /ˈkwaɪnaɪn/, /kwɪˈniːn/ or UK: /ˈkwɪniːn/ KWIN-een Trade namesQualaquin, Quinbisul, others[1]AHFS/Drugs.comMonographMedlinePlusa682322License data US DailyMed: Quinine US FDA: Quinin...

Health professions graduate school Touro University CaliforniaMottoTo Serve, To Lead, To Teach[1]Typeprivate graduate schoolParent institutionTouro College and University SystemReligious affiliationJudaismPresidentAlan Kadish[2]Academic staff105 full-time,[3] 87 part-timeStudents1,248 [4]LocationVallejo, California, United States38°05′13″N 122°15′51″W / 38.087°N 122.2643°W / 38.087; -122.2643CampusMidsize City,[5] 44 ...

The Clash discographyThe Clash live in Oslo, 1980.Studio albums6Live albums2Compilation albums9Video albums2Music videos13EPs2Singles31Box sets4 The discography of the British punk rock band the Clash consists of six studio albums, two extended plays, two live albums and 31 singles. 1977–1978 The Clash's first official recording was the single for White Riot, released by CBS Records in March 1977. In April, CBS released their self-titled debut album, The Clash, in the United Kingdom, but re...

Filmmaking in the Russian Empire This article does not cite any sources. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Cinema of the Russian Empire – news · newspapers · books · scholar · JSTOR (November 2022) (Learn how and when to remove this template message) The Cinema of the Russian Empire (Pre-reform Russian orthography: Синематографъ Росс...

هذه المقالة يتيمة إذ تصل إليها مقالات أخرى قليلة جدًا. فضلًا، ساعد بإضافة وصلة إليها في مقالات متعلقة بها. (يناير 2016) المقالة الرئيسية: الحرب الأهلية اليمنية (2015) التدخل العسكري في اليمن جزء من الحرب الأهلية اليمنيةصراع السعودية وإيران بالوكالة غارة جوية في مخازن الصواريخ و...

Bridge in India Vembanad Rail BridgeCoordinates10°00′22″N 76°15′29″E / 10.006°N 76.258°E / 10.006; 76.258CarriesRailCrossesVembanad LakeLocaleKochi, Kerala, IndiaOther name(s)Edappally - Vallarpadam BridgeMaintained byRail Vikas Nigam LimitedCharacteristicsDesignBeam bridgeMaterialPrestressed ConcreteTotal length4.62 kmWidth5-metreHeight7.5-metreNo. of spans132HistoryConstructed byAfcons InfrastructureConstruction startJune 2007Construction end31 March...

Office in Pasig, PhilippinesRobinsons Equitable TowerRecord heightTallest in the Philippines from 1997 to 1998[I]Preceded byRufino Pacific TowerSurpassed byPetron MegaplazaGeneral informationStatusCompletedTypeOfficeLocationOrtigas Center, Pasig, PhilippinesCoordinates14°35′21.82″N 121°3′35.74″E / 14.5893944°N 121.0599278°E / 14.5893944; 121.0599278Construction started1995Completed1997Opening1997OwnerRobinsons Land CorporationHeightRoof175 m (574.15...

Federal territory and capital city of Malaysia Federal capital city and federal territory in MalaysiaKuala LumpurFederal capital city and federal territoryFederal Territory of Kuala LumpurWilayah Persekutuan Kuala LumpurOther transcription(s) • Jawiولايه ڤرسکوتوان کوالا لومڤور‎ • Chinese吉隆坡联邦直辖区 (Simplified)吉隆坡聯邦直轄區 (Traditional)Jílóngpō liánbāng zhí xiáqū (Hanyu Pinyin) • Tamilக...

Ghanaian fashion design brand Pistis Ghana LtdTypePrivately heldIndustryFashionFounded2008; 15 years ago (2008)FounderKabutey and Sumaiya DzietrorHeadquartersAccra, GhanaProducts Gowns Ready-to-wear Number of employees60 (2020) Pistis Ghana is a Ghanaian fashion brand based in Accra. It was founded by husband-and-wife duo Kabutey and Sumaiya Dzietror in 2008 after graduating from Joyce Ababio's Vogue Style School of Fashion and Design.[1][2] Pistis means fait...

Indian freedom activist and the wife of Mahatma Gandhi This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Kasturba Gandhi – news · newspapers · books · scholar · JSTOR (March 2016) (Learn how and when to remove this template message) Kasturba GandhiGandhi in 1915BornKasturbai Gokuldas Kapadia(1869-04-11)11 Apri...

LiechtensteinAssociation nameLiechtenstein Ice Hockey FederationIIHF CodeLIEIIHF membershipOctober 4, 2001PresidentMartin Rudisuhlihttp://www.leiv.li The Liechtenstein Ice Hockey Federation (German: Liechtensteiner Eishockey und Inline Verband (LEIV)) is the governing body of ice and inline hockey in Liechtenstein. External links International Ice Hockey Federation Liechtenstein Ice Hockey Federation vteNational members of the International Ice Hockey FederationFull members Australia Austria ...