Spaghetti code is a pejorative term for computer code with a complex and tangled (like strands of spaghetti) control structure. It is characterized by the use of the GOTO instruction or other unstructured, unconditional branching. This type of undisciplined code is almost impossible to trace or debug due to its complexity and disorganization. Instead, code should be structured and modular.
| Structured | Spaghetti |
|---|---|
START: PERFORM DOG PERFORM CAT PERFORM FISH PERFORM BIRD PERFORM FROG EXIT. DOG: WALK THE DOG RETURN CAT: PUT OUT THE CAT RETURN FISH: FEED THE FISH RETURN BIRD: COVER BIRD CAGE RETURN FROG: SING TO THE FROG RETURN |
START: GOTO MAMMALS DOG: WALK THE DOG GOTO CAT MAMMALS: GOTO DOG FISH: FEED THE FISH COVER THE BIRD GOTO FROG CAT: PUT OUT THE CAT GOTO FISH-AND-FOWL FISH-AND-FOWL: GOTO FISH DINOSAUR: BECOME EXTINCT GOTO START FROG: SING TO THE FROG EXIT. |