Spaghetti code

   

A plate of spaghetti looks twisted and tangled, which is where the name for spaghetti code comes from.
Enlarge
A plate of spaghetti looks twisted and tangled, which is where the name for spaghetti code comes from.

Spaghetti code is a pejorative term for a computer program code with a complex and tangled control structure, especially one using many GOTOs, exceptions, threads, or other "unstructured" branching constructs.

It is named such because program flow tends to look like a bowl of spaghetti, i.e. twisted and tangled. Also called kangaroo code because such code has so many jumps in it.

Spaghetti code is an example of an anti-pattern.

Here's an actual example of Java spaghetti code taken from a production codebase:

 if (aAguId == null || new Integer("0").equals(aAguId))
     ...

The author could have just written:

 if (aAguId == null || 0 == aAguId.intValue())
     ...

which not only does the same thing but is easier to read, uses less memory and requires fewer instructions. True spaghetti code, of course, can get much more convoluted, but this simple example displays the fundamental spaghetti principles: make your code more convoluted and complex than it needs to be and make people think hard to understand it.

See also

References

This article was originally based on material from the Free On-line Dictionary of Computing, which is used under the GFDL.

External links



de:Spagetticode

Retrieved from "http://www.mywiseowl.com/articles/Spaghetti_code"

This page has been accessed 510 times. This page was last modified 12:49, 14 Nov 2004. All text is available under the terms of the GNU Free Documentation License (see Copyrights for details).