Clean Code: A Time-Saver, Not a Time-Waster
Clean code is often perceived as time-consuming, but it actually offers significant long-term benefits.
I have heard it many times: for my MVP I am not focusing on clean code, I will refactor it later when I have verified my idea. I understand you want to build your product as fast as possible, but...
There are two questions I would like to ask:
what is your standard way of coding?
what exactly will be faster?
Let’s try to understand that way of thinking and validate it.
Quick and Dirty Coding
So, what does clean code mean to me? Debating what constitutes clean code can take hours, maybe days.
I would say that the shortest definition would be code with good naming conventions for functions and variables, one responsibility functions, and easy to understand organisation of the code. That's all for a good start for me.
Follow this definition: Where do you see your options to earn time? A few minutes (seconds with the AI assistant) for better naming? A few seconds to create separate functions? Let's say you just earned an hour, what is the real cost of that?
The Long-Term Costs of Dirty Code
You have created your app, have your first clients, the first bugs are noticed, and it is time to add new features. Would be good to add some at least unit tests, maybe add someone new to the team.
And now the time you earned in the first iteration shows the real cost of your choice.
You think that you have earned the time for your project in the first step, and then the real work comes.
It takes longer to debug because you have to track down the messy conditions in the long functions that you have written. You decide not to write unit tests because your code doesn't use dependency injection. So you can't mock things that should be mocked.
When new developers join the team, instead of spending time working on the code, you have to explain your code to them. Because your names are not clear, you have to think about what past you mean by writing this stuff.
Typically, developers decide to leave the code as it is because there is no time to refactor, and they sink further into this quagmire.
Why We Believe Clean Code Takes Longer
The biggest reason for this, in my opinion, is that many developers do not have an education in the principles of clean code from the start. In a world where it's really easy to start writing code, programmers want to create things as quickly as possible (which is good), but at any cost, which makes them skip the basics such as writing clean code.
So, because you didn't learn how to write good code from the beginning, after a certain amount of time with a certain set of habits, you're going to feel uncomfortable when someone tells you to change your standards.
The second thing I want to mention is that there are a lot of influencers who have no basic knowledge of coding. They show code that works, but their standards are really low, and a lot of developers learn from those sources.
Conclusion
My summary will be just one sentence.
Writing clean code takes more time only for the developers who have to change their standard way of coding to clean code.