In Praise of Spaghetti Code

Retrieved from

Computer Science and Technology.

Spaghetti code is not getting any respect. Software experts denigrate it; coding classes avoid it like the plague; and when students go out into the world, they spend inordinate amounts of time trying to follow their mentors’ instructions. This unalloyed disparagement of spaghetti code is unfortunate, because we owe so much to it.

Wikipedia defines spaghetti code as “a pejorative phrase for source code that has a complex and tangled control structure, especially one using many GOTO statements, exceptions, threads, or other ‘unstructured’ branching constructs [1].” This certainly sounds esthetically unattractive and technically unsound. And indeed, many software disasters can be attributed to spaghetti code. Perhaps the first prominent crusade against it was launched back in 1968 when Dijkstra wrote about the “undesirability of the go to statement” [2][3], to the point that some have called it “evil.”

Yet despite this relentless opprobrium, we cannot restrain ourselves from generating ever more of spaghetti code. There are many reasons for it [4]. Particularly important is the development of ever more complicated systems, in which even the use of the approved software engineering methodologies at low levels leads to complications at higher levels [5]. Technical terms, such as “high cyclomatic complexity,” are often used to describe the results, which are similar to those complained about as resulting from GOTO statements in earlier times. So the more evocative term “spaghetti code” is still used, even if in a different sense than it was originally. But the disparagement of it is just as strong, if not stronger.

The fact is, though, we could not live without spaghetti code. So we should abandon the futile and sometimes counterproductive effort to eradicate it, and learn to live with it and occasionally purposefully employ it.

By any reasonable definition, practically all large software systems, and especially the popular operating systems such as Windows or Linux—with their tens of millions of lines of code—can be safely characterized as spaghetti code. And yet that is what our information technology services depend on, and therefore so does our whole society.

So yes, we do have to put up with having to reboot our systems. Occasionally an airline gets grounded for a few hours or even a few days. Thus we do suffer many annoyances, and our information technology systems are barely usable and hard to maintain. But they sort of work, and we could not run an economy as complex as ours without them.

Beyond our inability to completely avoid spaghetti code, and our daily dependence on it, there are some unappreciated benefits to it. It deserves some respect even for purely intellectual reasons. The standard view propounded by theoreticians and practitioners was software should be thought of in the idealized form of a fully specified, understood, and correctly functioning system. In practice, though, as most people have implicitly come to understand, large software systems are more like pets or farm animals. Those creatures do behave with some degree of predictability, and with enough coaxing or whacking can usually be persuaded to deliver something close to what is desired. But they do have minds of their own, minds that we understand very imperfectly.

Information technologies show many similarities to domesticated animals. With the advent of ever more complicated systems, especially as techniques such as neural networks penetrate ever further, it is becoming clear we will have decreasing insight into the internal functioning of our software. That of course is a problem, but it does offer some benefits.

Complicated code that is only roughly understandable and predictable helps provide the “social grease” that helps people function. Instead of saying “the dog ate the homework,” students now claim, with greater plausibility, “the computer crashed and wiped out the files.”

On a more practical level, spaghetti code (and various other software deficiencies that are widely condemned) has advantages for professionals, in providing job opportunities. Even COBOL skills offer gainful employment to multitudes of programmers.

It is not only employees who benefit from spaghetti code, so do their employers. When modifying iPhones to remove limitations imposed by the manufacturer was made legal, part of Apple’s response was to declare “the vast majority of customers do not jailbreak their iPhones as this can violate the warranty and can cause the iPhone to become unstable and not work reliably [6].”

Do you think Apple would like their code to be of the nice, clean, modular variety that is advocated by the mainstream software experts? Or would they prefer it for any unauthorized modifications to be hard to carry out without destroying basic functionality? More generally, you do not have to worry about piracy if your code barely works, and then only works with constant security or other tweaks. The need for users of the code to get a steady stream of updates keeps them tied to the vendor. So yes, maintenance of the system is a pain, but it does have advantages.

Code obfuscation should be a basic tool that is widely taught, and not treated like a joke [7]. It is not perfect, but it often works and enables even nice, clean, structured programs to masquerade as spaghetti code.

In addition to the business benefits of limiting piracy for software vendors , spaghetti code does have positive effects (in addition to the widely recognized negative ones) in enhancing all of computer and network security. Digital forensics, which is key to maintaining some semblance of security in cyberspace, depends crucially on spaghetti code. The hostile hackers get tangled up in the systems they break into. Further, being human, they cannot avoid creating spaghetti code of their own in their malware [8]. This is then often the key to locating intrusions and tracing the perpetrators.

Spaghetti code is not an unalloyed good that we should embrace wholeheartedly. But neither is it totally evil. We should recognize it does have some positive benefits, tolerate it when it cannot be avoided, and diligently work to eradicate it where it causes serious harm. This is not an easy recipe to follow. But who ever said that computing is easy?

About Sofia University

Sofia gold seal

Sofia University is internationally recognized as an academic leader in transformational research and teaching. The Sofia educational model offers students not only a solid intellectual foundation, but an extraordinary opportunity for deep transformational growth and personal experience of the subject matter. Through a well planned blending of technology, science, business and the school’s 40 plus years of leadership in humanistic and transpersonal psychology, graduates can create a substantial, real-world impact.

Sofia University offers a variety of innovative undergraduate and graduate degree programs with a choice of delivery modalities for students on campus and abroad.

Learn more about our programs.

Leave a Reply

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

You are commenting using your 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

Blog at

Up ↑

%d bloggers like this: