The Spaghetti Code
Source: Google image search

The Spaghetti Code

कालाद् बहोः कान्यपि दुष्पदानि लब्धानि मन्दः परितो विकीर्य ।

छिद्राणि लोष्टैरथ पांसुभिश्च सम्पूरयन् विस्मयते विलज्जः ॥

-शिवलीलार्णवः १.४१

kālād bahoḥ kānyapi duṣpadāni labdhāni mandaḥ parito vikīrya ।

chidrāṇi loṣṭairatha pāṃsubhiśca sampūrayan vismayate vilajjaḥ ॥

-śivalīlārṇavaḥ 1.41

A shameless idiot acts amazed after filling the gaps (in his poem) by picking up several offensive words that are randomly strewn around him over time, much like filling holes with mud and sand.

Consider the enormous towers being constructed in cities like Mumbai. It goes without saying that the labourers must construct modest shanties for themselves to sleep in while they work. Building sky-scrapers takes time, and the families of the labourers eventually make their homes in the shanties and find employment nearby. When the structure is finished in a few years, the workers will already be well settled in their shanties. As a result, modest shanties are built everywhere around grand houses. Similar phenomenon in the coding world is what we call spaghetti code.

Modern society's pervasive digital evolution demonstrates the enormous strides software engineering has made over the past few decades. New innovations and old legacy code go side-by-side, as adaptation to changes always is a challenge. Any software company worth its salt will have a team devoted to maintaining legacy software and regularly issuing bug-fixing updates. They may also have teams assigned to migrate the old software/ hardware solutions to new ones. Modifying existing code, most of the time means generating the spaghetti code. This gets exacerbated when the original architect of the software moves on and new developers take over in fixing the defects. Not understanding the underlying architecture may churn out more spaghetti code, creating new defects while fixing customer-reported issues.  

To comprehend another form of tradeoff that programmers confront, let's think about a typical case of cooking rice. Before cooking, rice is usually washed several times, maybe to remove impurities. However, some people think that over-washing rice degrades its nutritional value. It seems like a cook's challenge is always choosing between removing pollutants and maintaining nutritional content. Similar trade-offs between performance and security are required in designing software . If there are too many checks and balances in the code, the software's performance may suffer. However, the customer may receive a faster product but could also be vulnerable to security breaches if one decides to disregard these tests in an effort to speed up response time. This also results in spaghetti code, when the programmer tries to fix the security vulnerability over performance issues or vice versa.

This verse from Sri Neelakantha Dikshita on a poet's dilemma is applicable to software architects/ programmers as well -

क्वार्थाः क्व शब्दाः क्व रसाः क्व भावाः क्व व्यङ्गयभेदाः क्व च वाक्यरीतिः ।

कियत्सु दृष्टिः कविना न देया किमस्ति राज्ञामियतीह चिन्ता ॥ १-३०॥

kvārthāḥ kva śabdāḥ kva rasāḥ kva bhāvāḥ kva vyaṅgayabhedāḥ kva ca vākyarītiḥ ।

kiyatsu dṛṣṭiḥ kavinā na deyā kimasti rājñāmiyatīha cintā ॥śivalīlārṇavaḥ 1.30॥


A poet must consider the words used, their meanings, their expressions, the underlying feelings, many sorts of satire, and the arrangement of sentences (even while writing a single line); does a king ever confront similar difficulties?


Notes

Accidentally I came across the work of Sri Neelakantha Dikshita's , a 17th century Sanskrit poet and found his satire still relevant after 4 centuries. In his book of 22 chapters, Śivalîlàrnavah, he dedicates the first chapter to poets and poetry. Since poetry means creativity and, project management and coding also need creativity to some extent, some of his verses resonate with the world of software development. So I decided to pick up a few verses and map them to relevant coding principles and share them here.

Acknowledgement

Credit goes to Dr Shankar Rajaraman and Anand V. of CAHC, Jain University, Bengaluru for introducing me to Sri Neelakantha Dikshita's work. I am very grateful to Dr Shankar Rajaraman for patiently explaining the first chapter of Śivalīlārṇavaḥ with the nuances and deeper meanings. This concept of Spaghetti code was explained to me by Mr Simon Crase from New Zealand a long time back. I feel, you learn more at work from co-workers and customers and getting your hands dirty at work than just from memorising texts at schools and colleges to pass the exams.

References

śivalīlārṇavaḥ by Mahakavi Sri Neelakantha Dikshita https://sanskritdocuments.org/doc_shiva/shivalIlArNavanIlkaNThadIkShita.html

Interesting article. The high rise towers surrounded by shanties is a good observation of how urban spaces are getting organized. This is the worry for the present day governments (kings). Nilakantha exaggerates when he says a poet is more concerned with his profession than the king. Your love for Sanskrit is remarkable.

The Spaghetti Code falls under the (anti) design pattern - the Big Ball of Mud or Shanti Town. For those interested into that software design pattern/ anti-design pattern for the same, this link summarises it well http://www.laputan.org/mud/mud.html#BigBallOfMud

Like
Reply

To view or add a comment, sign in

More articles by Warija Adiga

  • A dog' s tail - शुनᳲ पुच्छम्

    Foreword When one embarks on learning one of the world's oldest surviving languages, it can feel as though the world…

    30 Comments
  • Agenda Setting

    Communication is key to success in the corporate world. What we present and how we present are equally relevant.

  • Sanskrit - Ancient language for modern management principles

    As I had mentioned in my earlier posts, I will keep on sharing about Sanskrit and IT connection, in this forum. Sharing…

  • Looking more into Sanskrit and the IT world

    Before we explore more on Sanskrit and its beauty, I would like to share some challenges the language is facing as…

    4 Comments
  • A leap from IT to Sanskrit

    Leap from IT to Sanskrit studies I quit Intel in 2013 May to take a break from my active IT career and smell the roses.…

    20 Comments

Others also viewed

Explore content categories