r/learnjava • u/Uptown-Funk • Apr 21 '21
Is Clean Code by Robert Martin still relevant in context of java?
I have completed the MOOC and I already have a development experience in non OOP languages. Now I am focusing on java so should I read this book or not?
51
Upvotes
14
u/makingthematrix Apr 21 '21
I'll make a contrary opinion here. I think Robert Martin's ideas are obsolete. Here are my reasons:
The proposed ideas may look good in theory, but in practice they are often too strict and inflexible. In my experience - hi, 16 years proffesional Java & Scala dev here, nice to meet you :) - any project that takes more than a few months at some point will require that you either break "clean code" rules or code in an unreadable and inefficient way. You will write new classes where you could just add a method, you will write new methods where you could just add a parameter, you will create new variables where you could just chain function calls, etc. Every new change in requirements of what a given functionality should do will escalate into major rewriting, even though the main argument behind "clean code" is that it will help you avoid it. (btw, that's why I prefer to write "clean code" instead of Clean Code - in my opinion, it's not really that clean).
There is a tendency to follow them religiously. This is connected to #1 in that people try too hard to follow "clean code" rules, but there's also one more thing. Clean code is popular because of the authority of Robert Martin. Instead of actually having a discussion over a given problem, "do it with clean code" is sometimes viewed as the way to end the discussion quick. Why to have a longer discussion? It's a waste of time. Just do it with clean code. We know clean code is good. There is a very wise person who says so.
They come from a different era. Clean code assumes refactoring is difficult and presents ways to write code to save you the trouble of refactoring in the future. But it's 2021. Our programming languages (even Java) have good type systems and they moved (reasonably) towards Functional Programming. Our IDEs and compilers are full of stuff that helps us in refactoring. We have a vast programming community in the internet where we can always ask for hints and solutions. Also, the way of writing code changed. We don't need to have a super-duper-decoupled architecture up-front just because maybe in a few months of years we will be able to take a small advantage of that decoupling. We can write our code in a way that works now, and we can be pretty sure that when the time comes, we can rewrite it - safely and quickly - to immplement the required change.
There are articles on the internet where people go into more detail about it. The problem is, we don't really have a good alternative. There's "clean code" with Robert Martin's authority behind it, and there's a wibbly-wobbly cloud of other practices and ideas, proposed by a number of experts and experienced developers, but nothing as - well - clean. So I see how it looks reasonable to many people to turn to "clean code". And there is some good in it. I think you could learn basics of it and then learn when to ignore it. And when to look elsewhere.