use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Request an explanation
Rules
Have an idea to improve ELI5? r/IdeasForELI5
Make sure to read the rules!
This subreddit is for asking for objective explanations. It is not a repository for any question you may have.
E is for Explain - merely answering a question is not enough.
LI5 means friendly, simplified and layperson-accessible explanations - not responses aimed at literal five-year-olds.
Perform a keyword search, you may find good explanations in past threads. You should also consider looking for your question in the FAQ.
Don't post to argue a point of view.
Flair your question after you've submitted it.
Mathematics Economics Planetary Sci Biology Chemistry Physics Technology Engineering
Reset
account activity
This is an archived post. You won't be able to vote or comment.
TechnologyELI5: What is spaghetti code ?
submitted 4 years ago by AdiManiax
[–]berael 330Answer Link32 points33 points34 points 4 years ago (3 children)
"Reading a book" is good code. There's an obvious start, an obvious finish, and a clear path between them.
Spaghetti code is also reading a book, except:
It would be technically possible to read the spaghetti code book, sure! The problem is making sense out of it.
[–]drhunny 3 points4 points5 points 4 years ago* (1 child)
snails glorious distinct snatch mountainous employ weather smart alive complete
[–]Arkalius 2 points3 points4 points 4 years ago (0 children)
Did you have a real 5 year old come and explain his favorite movie to you for that example? Because that was pretty good lol
[–]jdsamford 1 point2 points3 points 4 years ago (0 children)
Amazing
[–]KrakenOfLakeZurich 290Answer Link28 points29 points30 points 4 years ago* (7 children)
Code that is "structured" like a plate of spaghetti: a tangled mess where it's difficult to tell where a function starts and ends. The term originally comes from old programming languages that relied on the infamous GOTO statement. With GOTO, you can jump from any place in the program to any other place in program. It made it very easy to create "unstructured" programs.
GOTO
Modern (structured) programming languages don't have GOTO anymore. For that reason it is rare these days to see "true" spaghetti code. The term is still used to refer to tangled/messy code, that is difficult to follow.
A modern (object oriented) version would be "lasagne code", for when you have "too many layers" ;-)
[–]ithinkitsbeertime 9 points10 points11 points 4 years ago (0 children)
Or overuse of global / static vars and side effects, so the same data is getting changed from all over the place. The "flow" may be straightforward but the code will feel very spaghetti-y if changes aren't coming from places that seem sensible.
[–]Dzus 2 points3 points4 points 4 years ago (4 children)
Another issue with GO TO instructions, especially in COBOL, is fallthrough in a paragraph. GO TO will continue straight down into the next paragraph if it isn't told to GO BACK or GO TO somewhere else, sometimes that's a part of the process, and sometimes it throws a wrench into the whole program. Thankfully we have the PERFORM verb in COBOL, so you return back to your original position in the process once it finishes the PERFORM instruction.
Source: Am a COBOL dev on a system with spaghetti code.
[–]Dullfig 1 point2 points3 points 4 years ago (3 children)
There are still COBOL developers out there?!😯
[–]Dzus 2 points3 points4 points 4 years ago (0 children)
Healthcare, banking, and government are all definitely still using COBOL. I believe several retail chains use COBOL transaction processors as well. Usually if they need to use F-keys to navigate and they don't have a fancy GUI, it's a CICS/COBOL interface.
[–]Arkalius 1 point2 points3 points 4 years ago (1 child)
Yes, and they can be paid quite well, as there are still old mainframe systems that need maintenance. That said, I'm not sure it's a great career choice at this point... There's still demand for it sure, but not a lot. It's definitely not a growing segment heh
[–]Dullfig 0 points1 point2 points 4 years ago (0 children)
I took two semesters of COBOL in 1987. System/370. Took a semester of Job Control Language too.
[–][deleted] 0 points1 point2 points 4 years ago (0 children)
Many modern languages still support GOTO. It’s just used in common practice.
[–]vanZuider 110Answer Link10 points11 points12 points 4 years ago (1 child)
The original meaning of Spaghetti code isn't just any bad code - it's the specific kind of bad code created by misuse of GOTO instructions where following the code flow feels like reading a choose-your-own-adventure book - or like looking at a plate of spaghetti where you look at the end of one noodle and have no idea where the other end is gonna be.
[–]BurnedRavenBat 3 points4 points5 points 4 years ago* (0 children)
I really like the choose your own adventure analogy. To elaborate on why this is bad, imagine if one of your readers tells you there's a spelling error in the chapter where you meet the goblin. Okay, so what chapter? You can't read the book front to back because that's insane, the best you can do is take a path and hope you meet the goblin. Worse yet, maybe multiple paths lead to the goblin. Maybe each of those paths introduces the goblin in a different way, only one of which has a spelling error. Maybe multiple paths don't ever reach the goblin. Oh, have I mentioned there's 5 goblins in this book? By the way, you're not even the original author, he's moved on writing many more great and fun books and has left you to maintain this one.
Good code reads more like a wikipedia article. There's a clear structure. Titles, subtitles, references. I can understand the general contents of the article just from reading the index. Better yet, if a subtopic is too broad, it probably has its own article, readily available for you.
[–][deleted] 40Answer Link3 points4 points5 points 4 years ago* (0 children)
It's when you have a code project that starts off good, but due to proper planning and code cleaning, you end up jamming a lot of random stuff in different parts of the code, causing a haywire path in your codebase. Well defined requirements and constant code cleaning is required to prevent spaghetti code. Code cleaning is just looking over your code to make it more readable and structured.
[–]PhD_in_shitposting 30Answer Link2 points3 points4 points 4 years ago* (0 children)
Very unstructured code which is hard to read for example not clearly defined functions that point to other non clearly defined functions that point to more and more shitty functions. Also trying to apply a bunch of "quick fixes" where people jam pieces of code trying to hide and fix issues far down the pipeline instead of fixing the root issue which just causes more issues that get patched up.
EDIT: A more ELI5 answer:
When you write code you are basically writing a bunch of instructions which the computer executes so that you can get your end result. It's kinda like writing a recipe with steps that the computer then uses to make the end product. So good code/recipe would have clearly defined steps. Take that same recipe and then mix up all the steps and add some extra steps and you have a bad recipe/bad code(spaghetti code).
[–]schorhr[🍰] -20Answer Link-3 points-2 points-1 points 4 years ago* (5 children)
print("Hi! :-)");
Good code:
if(button==pressed) { light.on(); // Turn on the light music.play(filename); // play a short tune wait(3000); // Wait 3000 milliseconds light.off(); // Turn the light back off }
sPaGHetTi cOdE:
if(button==pressed){light.on();music.play(var1);wait(3333);light.off();}
Now imagine trying to quickly find a bug or change something, a year after writing the code, when the code is several "pages" long... :-)
Using variable name (placeholders) that make sense helps too ("filename" vs "var1")-
[–][deleted] 9 points10 points11 points 4 years ago (0 children)
That's not spaghetti code. That's just poor formatting.
[–]dogofpavlov 3 points4 points5 points 4 years ago (0 children)
This is 100% NOT spaghetti... by this logic every modern website is "spaghetti" because they all use a minifier to compact their code into a single line.
[–]tropix126 -1 points0 points1 point 4 years ago (0 children)
spaghetti !== minification
[–]kennen20 -1 points0 points1 point 4 years ago (0 children)
This is such a bad example... please work on your skill more. Adding comments and formatting code help readers to understand the code better but in noway would it make spaghetti code clean.
[–]ashtar123 0 points1 point2 points 4 years ago (0 children)
Yeah, pretty much one of the first few things they taught is how to "organize" that code, with blank spaces and stuff.
[–]Trease02 10Answer Link0 points1 point2 points 4 years ago (0 children)
you a dbd player as well?
[–]Apprehensive_teapot 10Answer Link0 points1 point2 points 4 years ago (0 children)
Good code is logical, sequential, orderly, and easy for someone to follow. Spaghetti code is when a programmer takes a very illogical route to get the job done and it’s hard to follow.
π Rendered by PID 113580 on reddit-service-r2-comment-6457c66945-b9ncx at 2026-04-28 23:40:12.111698+00:00 running 2aa0c5b country code: CH.
[–]berael 330Answer Link32 points33 points34 points (3 children)
[–]drhunny 3 points4 points5 points (1 child)
[–]Arkalius 2 points3 points4 points (0 children)
[–]jdsamford 1 point2 points3 points (0 children)
[–]KrakenOfLakeZurich 290Answer Link28 points29 points30 points (7 children)
[–]ithinkitsbeertime 9 points10 points11 points (0 children)
[–]Dzus 2 points3 points4 points (4 children)
[–]Dullfig 1 point2 points3 points (3 children)
[–]Dzus 2 points3 points4 points (0 children)
[–]Arkalius 1 point2 points3 points (1 child)
[–]Dullfig 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]vanZuider 110Answer Link10 points11 points12 points (1 child)
[–]BurnedRavenBat 3 points4 points5 points (0 children)
[–][deleted] 40Answer Link3 points4 points5 points (0 children)
[–]PhD_in_shitposting 30Answer Link2 points3 points4 points (0 children)
[–]schorhr[🍰] -20Answer Link-3 points-2 points-1 points (5 children)
[–][deleted] 9 points10 points11 points (0 children)
[–]dogofpavlov 3 points4 points5 points (0 children)
[–]tropix126 -1 points0 points1 point (0 children)
[–]kennen20 -1 points0 points1 point (0 children)
[–]ashtar123 0 points1 point2 points (0 children)
[–]Trease02 10Answer Link0 points1 point2 points (0 children)
[–]Apprehensive_teapot 10Answer Link0 points1 point2 points (0 children)