Flying Spaghetti Monster

In Praise of Spaghetti Code

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?

References

[1] Wikipedia contributors. Spaghetti code. Wikipedia, The Free Encyclopedia;https://en.wikipedia.org/w/index.php?title=Spaghetti_code&oldid=783883152 (accessed June 15, 2017).

[2] E. W. Dijkstra, GO TO statement considered harmful, letter to the editor, CACM, vol. 11, no. 3, March 1968, pp. 147-48. http://dl.acm.org/citation.cfm?id=362947

[3] B. J. MacLennan, Principles of Programming Languages: Design, Evaluation, and Implementation, 3rd ed., Oxford Univ. Press, 1999. http://dl.acm.org/citation.cfm?id=300724

[4] B. Boehm, A view of 20th and 21st century software engineering, pp. 12-29 in Proceedings of the 28th International Conference on Software Engineering, ICSE ’06, ACM, 2006.    Available at http://www.ida.liu.se/~729A40/exam/Barry%20Boehm%20A%20View%20of%2020th%20and%2021st%20Century%20Software%20Engineering.pdf

[5] T. Mikkonen and A. Taivalsaari, Web applications — Spaghetti code for the 21st century, Sun Microsystems Technical Report SMLI TR-2007-16, June 2007. Available at http://ai2-s2-pdfs.s3.amazonaws.com/7856/3ec9ada8ec2266143c86b8ee9ae40b8d5925.pdf

[6] L. Kahney, Apple’s official response to DMCA jailbreak exemption: It voids your warranty, Cult of Mac, July 26, 2010. Available at http://www.cultofmac.com/52463/apples-official-response-to-dmca-jailbreak-exemption-it-voids-your-warranty/

[7] The International Obfuscated C Code Contest, http://www.ioccc.org/

[8] L. Constantin, Russian cyberspies blamed for U.S. election hacks are now targeting Macs, MacWorld, 14 Feb. 2017. Available at http://www.macworld.com/article/3169935/security/russian-cyberspies-blamed-for-us-election-hacks-are-now-targeting-macs.html