Spaghetti code is slang used to describe source code that's difficult for a human to read or follow because of how the original programmer wrote it. Below are examples of what can cause spaghetti code.
Spaghetti code examples
- Code is not organized and has portions of code that belongs elsewhere in the code.
- Code jumps around to other portions or files a lot making it harder to debug without also having to jump around a lot.
- Code contains goto statements that the programmer has to follow to an entirely new area of code.
- Code is not broken into conditional blocks or tabbed making it difficult to read.
Spaghetti code is considered bad practice because if errors are experienced, it is more difficult to locate what is causing the error. Spaghetti code can be reduced by keeping your code organized, formatted properly, commenting, using subroutines, and if possible breaking your code into sections.