Is Clean Architecture messy?
Pendulums swing right? At least this time they’re swinging in a direction which may actually do some good to our industry. Now, I think Robert C. Martin is a brilliant man and excellent marketeer . He no doubt has a lot of SOLID advice tangled into his Clean Code / Architecture / Agile Alliance and so on, but as with any “principle” if you follow it without questioning it, you’re likely going to end up with an unwieldy mess of a code base. If not, then kudos to you, in two decades of software engineering I’ve unfortunately never been lucky enough to see such a unicorn. What is perhaps the thing I dislike about the man behind it all is how “Uncle Bob” responds to criticism. Maybe that’s just like my opinion man, but if you’re curious just go and have a look at his personal “blog”. I recently read his response to Daniel Terhorst-North’s, in my opinion constructive, feed back on Clean Architecture and SOLID and it’s outright vile and nasty. Which isn’t too uncommon in the usenet generation of IT gurus, but even if you ignore this, a lot of the responses can basically be boiled down to “they completely misunderstood my principles”. To be fair, I think he’s often correct, but I think the problem is with the principles rather than the people who try to understand them. Partly because the principles are vague to a degree that is perhaps convenient if you’re in the business of selling consulting on said principles?
Now what was surprising to me as I looked into “Uncle Bob” was perhaps that the author behind Clean Code, Clean Architecture, The Clean Coder and even what I consider to be outdated books like Agile Principles and Patterns in C# and UML in JAVA. Is that he last worked professionally in actual Software Engineering a good 15-20 years before Python was even Invented. That’s right… The guy behind Clean * last did professional programming when Fortran was the most used Language in our Industry. So perhaps it’s not surprising that a lot of the principles aren’t working out so well here a good 20 years after they were written. I think it’s important for me to remind you that I think every principles, and every book I’ve read, has a lot of good points. The major issue I have with Clean is more along the lines of how “Uncle Bob” hasn’t exactly updated them to fit the criticism and research in Software Engineering from people who have actually followed them. Anyway, let’s dig into some of the criticism I think is on point.
Single responsibility
No doubt my favourite of the SOLID principles. Now to paraphrase “Uncle Bob” himself, he points out that this is the most misunderstood principles and admits that its name is a bit misleading. In his own words: SRP says that a class or a method should have only one reason to change. Which is still hilariously vague in my opinion, but if you’ve actually read his works and not just picked up on SOLID from the internet you’ll know it also tells you that the higher level of abstraction the less detail you’re supposed to include. What I think is perhaps the most common misunderstanding is that it perhaps should have been named “DON’T MIX LEVELS OF ABSTRACTION” rather than “single responsibility”. In none of his works “Uncle Bob” ever explains how you’re supposed to separate your portfolio from your assets; how you’re supposed to separate your assets from your computation and so on. As such it’s an easy principle to get wrong.
Even if you do get it right it still comes with a cost. What you give up is locality of behaviour, which is understanding what is going on with a piece of code
Last but not least people tend to over complicate their code
Recommended by LinkedIn
DRY
Another cool concept is that you should never repeat yourself. This is good advice for the most part, but as with any principle it isn’t free. With DRY you trade the ability to change requirements for reduce duplication. Typically this will be a very good trade for the programmer and a horrible trade for the business which pays the programmer to implement changes. You know this principle as a “Bird” or a “Car” or whatever abstraction you were taught. It works well when you have a duck, an ostrich and an eagle and only do the “fly”, “swim”, “run” part. What happens when you add “dive”? This is perhaps easy for the duck, but what about the eagle? Now you’ll need to add swoop. Then you’re adding behaviours such as nesting, eating, hunting and so on. How do you think your CLEAN code looks now?
In all likelihood it looks extremely messy. Especially if “you” was really ten people working on “Animal” as the top level abstraction over a period of five years. How rapidly do you think you could add a penguin, having to modify all those abstractions and their tests? If you duplicated your code and separated it by functionality, adding a penguin would be as easy as adding your first bird. Which is what your business cares about. Which is what, you, should care about because you’re in a service function and your sole existing is adding more business value
I could go on forever about how CLEAN is actually MESSY, but I think you’ve gotten the gist of my opinion on the matter. This wasn’t an easy opinion to form, it took me 20 years and I can assure you that it followed the five stages of grief. At first I didn’t want to believe that the foundation of my CS degree was wrong… I’m perpetually stuck with the frustration, however, because I have a side gig as an external examiner for CS students. Students who are, still, taught the same curriculum
YAGNI
You aren’t going to need it! Go pure concrete until you need that interface. Don’t abstract unless you, have, to! Now that was like my opinion man, as I pointed out from the very beginning, but what is yours?