What is spaghetti code?

There are few programmers who haven’t heard of spaghetti code. But few truly understand it. There are often first year students who ask why they shouldn’t use goto statements in their code. It’s hard for them to understand partially because they have little context. Spaghetti code is intrinsically linked with the use of goto statements. When Fortran first appeared, the goto statement was one of the languages core control structures. It provided jumps from one part of the program to another part – often in an extremely unstructured manner. Languages that followed like Pascal, C, Ada, all had goto statements.

So adding one goto statement to a program may not seem like a big deal. But it is, and students don’t truly understand this. Until of course they have re-engineered a “small” vintage Fortran program. Then they get a true feeling for how messy unstructured programs are – pure spaghetti. Consider the amount of “jumps” in the following small legacy Fortran program from 1966.


A full description of spaghetti code with examples, can be found here.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.