Spaghetti code

Updated: 04/26/2017 by Computer Hope

Spaghetti codeSpaghetti code is slang used to describe a program's source code that is difficult to read or follow by a human because of how the original programmer wrote the code. Below are some 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.

Kludge, Obfuscation, Programming terms