What is spaghetti code?

Federico A. Ramponi picture Federico A. Ramponi · Oct 12, 2008 · Viewed 39.2k times · Source

Can you post a short example of real, overdone spaghetti code, possibly saying what it does? Can you show me a little debugger's nightmare?

I don't mean IOCCC code, that is science fiction. I mean real life examples that happened to you...

Update

The focus has changed from "post some spaghetti code" to "what is exactly spaghetti code?". From a historical perspective, the current choices seem to be:

  • old Fortran code using computed gotos massively
  • old Cobol code using the ALTER statement

Answer

Brian Genisio picture Brian Genisio · Nov 28, 2008

To me, a more modern example of spaghetti code is when you have 20 dlls and every DLL references each other in one way or another. Your dependency graph looks like a huge blob, and your code hops all over the place with no real order. Everything is inter-dependent.