Coding is a way to communicate with a machine, by passing commands that the machine will operate. However, it is not only that, writing good and maintainable code is more about writing code for other humans than for a machine.
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
―Martin Fowler
The key to writing maintainable code is writing code that is easy to understand and obvious for those who are reading.
As developers, we spend the majority of our time reading code. Therefore, writing a clean code is crucial.
Indeed, the ratio of time spent reading versus writing is well over 10 to 1….
― Robert C. Martin, Clean Code: A Handbook of Agile Software Craftsmanship
According to Grady Booch Software Engineering chief-scientist at Software from IBM Research, a clean code is simple and direct. This means that anyone who reads the code will be able to understand what the code does because it is obvious.
Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designer's intent but rather is full of crisp abstractions and straightforward lines of control.
― Grady Booch
Based on this, one of the main keys to writing sustainable code is communication. Writing code that clearly communicates the intent.
Communication is the key to achieving a better and maintainable code. However, writing code that communicates clearly is not so easy.
A good starting point is learning design principles, design patterns, and effective techniques for writing clean code. These practices can help create code that is easier to understand and maintain. I wrote about it in these posts:
Perhaps the best way to write code that communicates well is simply by caring. A developer who genuinely care about the quality of the code they produce is more likely to create code that is clear and easy to understand. This is why I appreciate Michael Feathers' definition of clean code:
I could list all of the qualities that I notice in clean code, but there is one overarching quality that leads to all of them. Clean code always looks like it was written by someone who cares. There is nothing obvious that you can do to make it better. All of those things were thought about by the code’s author, and if you try to imagine improvements, you’re led back to where you are, sitting in appreciation of the code someone left for you, code left by someone who cares deeply about the craft.
― Michael C. Feathers
Conclusion
Writing maintainable code is crucial as applications grow in size and complexity. The key to achieving this is clear communication through your code. Writing code that other developers can easily understand helps create a sustainable application that is easier to maintain and evolve.
When we care about our code, we embrace a mindset of continuous improvement, always considering the best ways to express our ideas through the code. This approach not only improves clarity but also leads to better, more maintainable code in the long run.
If you care about writing better code, subscribe for free and stay tuned for more tips and updates to keep improving your skills.
References
Clean code - Robert Cecil Martin