Spaghetti code is a derogatory term for computer programming that is unnecessarily convoluted, and particularly programming code that uses frequent branching from one section of code to another. Spaghetti code sometimes exists as the result of older code being modified a number of times over the years.
Another part of the spaghetti analogy is the way that making a change to one part of the code can have unpredictable effects on the rest of the program, just as pulling on one strand of spaghetti can affect other strands of spaghetti that in ways that are not foreseeable. Techniques such as data hiding are often used to prevent similar problems in coding.
Procedural programming languages, such as COBOL and FORTRAN, depend upon the skill and diligence of the programmer to avoid ending up with spaghetti code. A subset of procedural programming known as structured programming, which enforces a structure within the code, was developed to circumvent such problems.
Spaghetti code or any type of hard-to-understand code is sometimes referred to as write-only code. Other variations on the Pasta Theory of Programming include lasagna code, which is likened to structured programming, and ravioli code, which is favored and likened to object-oriented programming (OOP).