What’s the difference between spaghetti code, lasagna code, ravioli code, and pizza code?

232 views

I’m starting to get into coding and these concepts make little sense to me.

In: 0

5 Answers

Anonymous 0 Comments

They are all metaphors to describe source code that is poorly designed in different ways. These are all subjective terms so the specifics will differ for each person.

**Spaghetti code** is really the only commonly used term. It originally meant code whose flow of execution is too complicated, traditionally this was caused by excessive use of GOTO statements to jump to different lines of code. Modern languages have better ways to deal with this (control flow: if, then, else, for, while, exit, continue etc) and possibly don’t even have an equivalent of the GOTO keyword. Nowadays it generally just means code that is difficult to read or follow; usually as a result of poor planning, tacking on changes instead of refactoring, and technical debt. The analogy to spaghetti is because reading the code is like following a string of spaghetti as it weaves and intertwines with other noodles.

The other terms are more recent, and nobody really uses them in practice. They’re all just playing off the same joke of comparing code to Italian food.

**Lasagne code** means code that has too many layers of abstraction. Abstraction is good, but too much of it means you’re going 20 layers up before you find the code that actually does the thing you’re looking for. The “layers” might be function calls, parent classes, event emitters etc depending on the system design, eg. Factory Pattern. Obviously because a lasagne dish is composed of layers of pasta sheets.

**Ravioli code** is a system that’s overly engineered to have a specific standalone component for every little function. Think microservice architecture taken too far. Ravioli pasta is small independent parcels of meat, cheese, vegetables etc.

**Pizza code** is an architecture that’s too flat. This is basically the opposite extreme to lasagne or ravioli; instead of layers of abstraction or independent standalone components, you have one big system with a lot of interdependency or thousands of lines of code in one big class etc. Like spaghetti code, pizza code is usually an outcome of poor design or lack of design, rather than over-engineering. It’s also not mutually exclusive to spaghetti, because a code base might both be too flat and difficult to untangle. Pizza obviously because it stuffs many ingredients into a single flat dish.

[This page](https://www.techtarget.com/searchsoftwarequality/tip/Fix-spaghetti-code-and-other-pasta-theory-antipatterns) describes these terms further and even mentions a few more. But remember, beyond *spaghetti code* these terms aren’t really used or even important. However as you become more experienced at coding you should definitely learn about the various anti-patterns that they describe, so that you can avoid them.

You are viewing 1 out of 5 answers, click here to view all answers.