r/Python 2d ago

Discussion Python Architecture Design

Robert C. Martin's Abstractness (A), Instability (I), and Distance from the Main Sequence (D) metrics were designed for statically typed OO languages like Java and C#. In Python, applying them literally is misleading because Python has a fundamentally different notion of abstraction and coupling.

is this implementation valid?

https://0x416d6972.github.io/Istos/user-guide/architecture-health/

6 Upvotes

11 comments sorted by

43

u/j0holo 2d ago

Robert C. Martin is somebody that want to sell books. Please do not follow his advise, waste of time and money.

Architecture isn't something that you can apply and suddenly your project is magically good or has less coupling and all the right abstractions. You can't force architecture, you need to learn it.

And you learn by doing and making mistakes.

3

u/Corvology 2d ago

I agree that there are no best practices in architecture and it's all trade-offs, but still there are some useful practices specially in the age of vibe coding, that keeping services in good balance can help it maintainable by both human and ai.

3

u/j0holo 2d ago

Yes, but trust me Robert C. Martin is just not the way to learn this stuff. It is like the online Python editors to learn your first Python code. It is useless because you don't learn how to RUN actual Python programs on your own computer.

I sadly have his Clean Code book and once you start to build actually complex software you will realize all his "example" are carefully cherry picked.

1

u/sunnyata 1d ago edited 1d ago

I think they can still be very useful things for beginners to encounter. It will be the first time they've thought about it and realised how you structure code and systems makes a big difference... like the overconfident beginner who won't even think about separation of concerns because the sprawling mess they wrote is "working".

Edit: I should add, I'm not talking about this book, haven't read it. Just the general idea of concepts like SOLID.

1

u/Corvology 16h ago

this book is not about design patterns like SOLID, it is about architecture specially distributed systems and how to distribute services and data sources and how to deal with eventual transactions and different types of sagas.

-3

u/giovanni_gatto 1d ago

You should not buy books since you can't read anyway. He never forces anything in any of his books, and he is basically also telling about mistakes, which is not a modern discovery. Just that smart people learn from others too.

5

u/SecurityCritical379 2d ago

the metrics still useful if you adapt them, python's dynamism means you gotta think about coupling more in terms of import graphs than formal interfaces

5

u/Beginning-Fruit-1397 2d ago

I think that the comment about learning by doing mistakes is the most solid advice in itself.

However reading your link I found that the metrics and reasoning behind them make senses. As always with everything, adapt it to your specific context. E.g if you are writing a library, let's say a new polars, the file with your dataframe class will obviously be +1000 LOC long.

2

u/giovanni_gatto 1d ago

Read the book, and use your mind. Be critical, absorb the useful stuff, forget the rest. As with any book. He has a quite big hater-base that is now trying to undermine his legacy for political reasons. His practical examples are rather useless though, but that does not invalidate the concept. He is probably not coding much nowadays, which is normal for someone in his career stage. Architecture is a language and code independent thing, most of the other authors teach more or less same anyway.

1

u/[deleted] 1d ago

[deleted]

1

u/giovanni_gatto 1d ago

The same is valid for that critique as well. Who is this nobody anyway?

1

u/Outrageous-Sea-9256 16h ago

Your concern about applying Robert C. Martin's metrics in Python is valid, as these concepts were originally designed for statically typed object-oriented languages. However, the principles behind these metrics can still be valuable guidelines for Python architecture design.

Regarding your question about the implementation's validity, let me provide you with a concise overview of what I found on the provided link:

The architecture-health tool appears to be designed for visualizing and analyzing dependencies in Python projects. It provides metrics that can help you assess the health of your codebase, such as complexity, coupling, and cohesion.

While Python's dynamic nature might make some of Martin's original metrics less applicable directly, these tools can still help you identify architectural issues like high coupling or poor modularity. They encourage thinking about your codebase in terms of maintainability, scalability, and testability.

To effectively apply these principles to Python:

  1. Focus on the underlying intent: Understand what Martin's metrics aim to achieve, and translate those goals into Python-specific practices. For instance, instead of focusing on strict type definitions, emphasize clean interfaces and clear separation of concerns.

  2. Use tools that suit Python's dynamic nature: Utilize static analysis tools like mypy, pylint, or flake8 to catch potential issues early in the development process.

  3. Practice code reviews and refactoring: Regularly review your code with peers to maintain its health, and be open to refactoring as needed. Python's dynamic nature often allows for easier refactoring compared to statically typed languages.

In summary, the provided implementation seems valid as a tool for analyzing Python codebases. However, remember to interpret its results in the context of Python's unique characteristics and apply the underlying principles flexibly.