Programming Italian Food Metaphor

Unstructured programming code was very hard to debug and was called “Spaghetti Code” because the control flow could be a tangled mess. The programmer might be setting flags here and testing them there to jump around in the code. Making corrections or adding features can make an even more complicated mess.

I extended this Italian food comparison for structured programming where the code is organized in layers. I called that “Lasagna Code” because Lasagna has layers of pasta between layers of meat, cheese, and tomato sauce. Structured programs are better-organized than unstructured code.

Object-oriented code encapsulates the details of subclasses with polymorphism. I call that “Ravioli Code” because the ravioli pasta hides the various contents, meat, cheese, seafood, veggies, etc. The ravioli can be treated the same on the outside but differs inside.

Once, in an interview with a corporate vice-president for a training company, he asked me to explain polymorphism. I did not mention Italian food. I said the term came from chemistry where there can be “many shapes” for chemicals that have the same chemical formula. In object-oriented programming, a class can have many subclasses that have different data and methods that take the same commands but behave differently for different subclasses. It is like an orchestra conductor who gives the same signals to all the musicians who then play their instruments according to the details of how their instruments work. The conductor does not have to know how to play the instruments because the musicians do.

The vice-president told me that was the first time he understood polymorphism!