CodeNewbie Community

Delia Ayoko
Delia Ayoko

Posted on

The Pasta Theory of Programming

Almost every developer insists that maintainable code shouldn't look like pasta. Various programming languages and frameworks have various tactics for warranting long-lasting and sustainable code. This theory should be helpful to developers and programmers to understand why unmaintainable code is unmaintainable.

The Pasta Theory Programming, therefore, is a menu of programming anti-patterns that talks about different kinds of programming frameworks as popular Italian pasta dishes; spaghetti, lasagna, ravioli, pizza, macaroni, stromboli, campanelle, baklava code. For better understanding, it'll be better if we focused on the main three and how they manifest in computer programs.

Spaghetti Code

The word spaghetti comes from Italian spaghetto which means "string". Spaghetti code is a term used to describe source code which is disorganized and sloppy, with a complex and tangled control structure. In the same way in which it is difficult to figure out the head of a spaghetto, it is hard to understand the relation between different sections of code because the program flow of the spaghetti code is a disconnected mess. The spaghetti code could be caused by several factors including short deadlines, lack of planning, or a complex program which has been continuously modified over a long life cycle.

How To Avoid Spaghetti Code: Every piece of code should hava a logical flow. Taking time to structure is an important factor, and planning how to progress with the code.

Lasagna Code

If sloppy and messy should be used to describe spaghetti code, then over-complicated and confusing are characteristics of lasagna code. Now, an Italian programmer would be right if he asked himself "why should I avoid lasagna code when lasagna itself is well-structured?" The problem with the lasagna code is the complexity. The lasagna code is overly structured, intertwined, monolithic and difficult to modify. It is abstracted with tightly connected layers, where each layer of code accesses services in the layers below through over-structured layers. This results in so much complication that a change in one layer results to a change in all others.

How to avoid Lasagna code: The codebase should be kept simple by being conservative with abstractions.

Ravioli Code

This should be the perfect design pattern for a codebase that seeks maintainability. The ravioli code contains small, self-contained classes of code which are analogous to individual pieces of pasta. It encourages separation of concerns and emphasizes a component-based code style, which makes testing and validation easier. However, the ravioli code has a thing with too much abstraction(just like the lasagna code). The codebase of the ravioli code can get out of hand quickly if programmers abstract further to an extreme extent, which is a signal for them to come back to earth.

Generally, coding practices against programming anti-patterns do not last forever. The programming patterns of the present could become the anti-patterns of the nearest future. In the long run, well-structured codebases might become old and smutty. Quick advice is to keep the codebase original and up-to-date for easy revision and maintenance.

Discussion (2)

natsal33 profile image

My code is so ravioli!

Cool post, I'll keep this in mind.

delia profile image
Delia Ayoko Author

Thank you!!