The Object-oriented Version of "Spaghetti Code" is "Lasagna Code" ?!
Skills:
API Design60%
Key Takeaways
Avoiding 'Lasagna Code' by applying object-oriented programming principles
Full Transcript
hey everyone um so I got some I I posted this quote uh yesterday no actually couple of days ago and I got some really interesting responses and um 140 characters is just too short to reply to this so um I decided to do a quick video reply also I'm trying out this new this new screencasting tool um so yeah so the quote was the object-oriented version of spaghetti code is of course lasagna code because you're ending up with too many layers and layers of abstraction that is and so yeah I got some really cool responses here from from ABI or I I hope I pronounced your name correctly ABI U he was saying or if you're in the microservices world ravioli code everything in its own pocket just thought that was hilarious that that's a great quote I'm I'm gonna make that another quote on uh that that I'm going to post and then uh assign you as as the author mention as the author as the author and we're going to see what happens um yeah now I want spaghetti I hope you're proud of yourself yes Tain that's I had spaghetti the last two days and I wonder if it has anything to do with that tweet so definitely had the same effect on me H all right and so Tobias writes uh how to avoid this is something wrong with the single responsibility principle and uh I think that's a pretty good question right because um well the the way I would interpret this is that the um uh too much of a good thing is a bad thing or you know it all depends on the the dose and I think it's with it is like that with any of these tools right like a tool or um a principle like the single responsibility principle it can be a really good thing for structuring your code and and writing better or more maintainable more readable code but you can also take it to an extreme and then you end up with something horrible right and whether that's called like lasagna code or or whatever um you know a giant like ball of twine code um you could totally take the single responsibility principle to an extreme I think where you basically you know you end up in this um your program is going to look like all of these joke examples for overly complicated Java programs right where you have like abstract Factory factories and all of these crazy design patterns applied in a way that just takes them you know into absurd territory and just absolutely makes them makes the result in code ridiculous and so I think like my interpretation here is that the quote is exactly about that I mean first of all like I think it's a bit of a joke but uh it it goes to show that you know too much of a good thing is a bad thing so if we if we go and just take you know object Orient orientation or the single respons a single responsibility Principle as like the only Hammer we have and we try to apply like to any nail we can find then I think we're going to end up with something horrible like lasagna code and um the way to avoid this is I think to know about many of these tools and to build up this kind of experience or feeling for when to apply a certain tool right in what situation um you want to apply one one of your many Tools in your toolbox so I think that will be that will be my strategy to avoid uh overlying one of these principles or one of these um these methodologies and you know it's the same with everything it's the same with like agile you know we probably all heard or worked at places where that was just taking that was being taken to you know too far you can be too agile and you can kind of you know you can spend all you know hours every week in Retros and all of these like meta things that don't actually help get the work uh help get the work done and so it's the same thing with these these the sign patterns and stuff so okay so a bit of a rambly answer there but I hope this helps you out and um I'm just going to post that to Twitter now see what happens
Original Description
We had a Twitter discussion about this quote and 140 characters was just too short for my reply: https://twitter.com/dbader_org/status/809944761427755008
This is the original quote:
"The object-oriented version of 'Spaghetti code' is, of course, 'Lasagna code'. (Too many layers)." – R. Waltman
The question came up of how to AVOID "lasagna code" in your own programs that use OOP patterns. Is there something wrong about using OOP? Is the Single-Responsibility Principle (SRP) flawed?
Watch the video to find out :)
* * *
Subscribe to this channel: https://dbader.org/youtube/
Dan's Weekly Python Newsletter: https://dbader.org/newsletter
Python Tutorials and Articles: https://dbader.org/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Real Python · Real Python · 32 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
▶
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
A better Python REPL – bpython vs python interpreter
Real Python
Introducing large-type.com – A Utility Website
Real Python
Reading Hacker News Without Wasting Tons of Time
Real Python
Forward References and Python 3 Type Hints
Real Python
Using Sublime Text as your Git Editor
Real Python
Python Code Linting and Auto-Complete for Sublime Text
Real Python
Make your Python Code More Readable with Custom Exceptions
Real Python
Write Better Tests with Sublime Text's Split Layout Feature
Real Python
How to Use Sublime Text from the Command Line
Real Python
Rename Variables with Multiple Selection in Sublime Text
Real Python
Sublime Text Settings for Writing PEP 8 Python
Real Python
Write Cleaner Python with Sublime Text's Indent Guides
Real Python
Sublime Text Whitespace Settings for Python Development
Real Python
Function Argument Unpacking in Python
Real Python
Python Code Review: Debugging and Refactoring "Conway's Game of Life" + Automated Tests
Real Python
Using "get()" to Return a Default Value from a Python Dict
Real Python
A Python Shorthand for Swapping Two Variables
Real Python
Python Code Review: Refactoring a Web Scraper, PEP 8 Style Guide Compliance, requirements.txt
Real Python
Click & Jump to Test Failures from the Command Line (iTerm2)
Real Python
Setting up Sublime Text for Python Developers
Real Python
Sublime Text + Python Guide Overview
Real Python
Python Code Review: Adding Pytest Tests to an Existing Python Web Scraper
Real Python
Type-Checking Python Programs With Type Hints and mypy
Real Python
A Shorthand for Merging Dictionaries in Python 3.5+
Real Python
Python Code Review Flask Web Security Tutorial + Virtualenvs, requirements.txt
Real Python
My Python Code Looks Ugly and Confusing – Help!
Real Python
Setting Up a Programmer Portfolio/Developer Blog – How To Get Started
Real Python
Do I Need a GitHub/GitLab/Bitbucket Profile as a Developer?
Real Python
Programmer Portfolio – Example and Walkthrough
Real Python
How to Get Your 1st Speaking Gig at a Tech Conference
Real Python
How to Build Your Public Speaking Skills as a Developer
Real Python
The Object-oriented Version of "Spaghetti Code" is "Lasagna Code" ?!
Real Python
Setting up Sublime Text for Python Developers – Lesson #1
Real Python
Cool New Features in Python 3.6
Real Python
"is" vs "==" in Python – What's the Difference? (And When to Use Each)
Real Python
Emulating switch/case Statements in Python with Dictionaries
Real Python
Python Function Argument Unpacking Tutorial (* and ** Operators)
Real Python
What Code Should I Put On My GitHub/GitLab/BitBucket Profile?
Real Python
A Crazy Python Dictionary Expression ?!
Real Python
String Conversion in Python: When to Use __repr__ vs __str__
Real Python
Method Types in Python OOP: @classmethod, @staticmethod, and Instance Methods
Real Python
Optional Arguments in Python With *args and **kwargs
Real Python
Python Context Managers and the "with" Statement (__enter__ & __exit__)
Real Python
Installing Python Packages with pip and virtualenv / venv
Real Python
"For Each" Loops in Python with enumerate() and range()
Real Python
Python Code Review: LibreOffice Automation and the Python Standard Library
Real Python
Managing Python Dependencies With Pip and Virtual Environments – Lesson #1
Real Python
Python Tutorial: List Comprehensions Step-By-Step
Real Python
Leveraging Python's Implicit "return None" Statements
Real Python
What's the meaning of underscores (_ & __) in Python variable names?
Real Python
Python Data Structures: Sets, Frozensets, and Multisets (Bags)
Real Python
Writing automated tests for Python command-line apps and scripts
Real Python
How to find great Python packages on PyPI, the Python Package Repository
Real Python
Immutable vs Mutable Objects in Python
Real Python
PyPI vs Warehouse, the Next-Generation Python Package Repository
Real Python
pep8.org — The Prettiest Way to View the PEP 8 Python Style Guide
Real Python
My Experience at PyCon 2017 in Portland
Real Python
Pylint Tutorial – How to Write Clean Python
Real Python
"Reverse a List in Python" Tutorial: Three Methods & How-to Demos
Real Python
Python Refactoring: "while True" Infinite Loops & The "input" Function
Real Python
More on: API Design
View skill →Related Reads
📰
📰
📰
📰
How Claude Projects Changed My Dev Routine
Dev.to · Gabriela Paulini Deutner
Stratagems #12: Mark Watched an AI Dashboard Take Over. The Muted Channel Was Still Speaking.
Dev.to · xulingfeng
Shravana — learn anything by listening (Gemini writes it, ElevenLabs voices it)
Dev.to AI
AI Tools that Actually Pay You Back: A Developer's Guide to Monetizing AI
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI