Spaghetti code

Updated: 11/12/2023 by Computer Hope
Spaghetti code

Spaghetti code is slang describing 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.

Note

Spaghetti code may also be called cruft or crufty 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.

Computer slang, Dead code, Kludge, Obfuscation, Programming terms