spaghetti code, spaghetti program

Spaghetti code is used pejoratively to refer to code whose complexity makes it difficult to discern processing streams and structure, and for which it is likewise difficult to debug or add functions.

Unpredictable flows of execution (resulting from heavy use of GOTO statements, etc.), in which erratic jumps in the program often cover wide distances in either direction, necessitate an expansion in the valid range for variables, which in turn renders it necessary to pore over the entire program when revisiting it for whatever purpose. Such a situation, in which the program is entangled in a difficult snarl from which it is impossible to surgically extract a few strands for examination and repair, is likened to a plate of spaghetti, and hence the term "spaghetti code".

The causes of spaghetti code and spaghetti programs are manifold, though typically they fall into one of two categories: either no uniform flow control was effected at the design stage, or a hodge-podge of functions was added to the program after its completion. Regardless, the means of preventing spaghetti programs are tied to clarifying the main flow of a program and formalizing its processes.

Spaghetti programs are associated with low quality, as the difficulty in maintaining them means they are often rife with bugs. In the event a spaghetti program requires modification, a higher quality product in less time can often be achieved by recreating the program from the beginning.