Clean Code … Is It Necessary?
IT Tips & Insights: A Softensity Software Engineer unpacks key insights from “Clean Code” by Robert C. Martin.
By Adam Cudak, Software Engineer
At the beginning of this article, I would like to answer the question in the title — yes, it is! Every programmer knows how many problems carelessly written code can cause, which is why it’s so important to know how to write high quality, clean code.
As a software engineer at Softensity, I’m lucky that my company makes sure that I can constantly develop, and together with my supervisor, we set annual goals for me to achieve. One of my goals this year was to read the book Clean Code by Robert C. Martin.
How Do You Write Good Code?
In his book, Robert C. Martin covers a lot of topics, including naming conventions, formatting, data structures and concurrency, to name a few. He describes not only how to write clean code, but how to recognize bad code.
After reading this book, I learned how important it is to prepare solid unit tests. Some assume that it’s enough to have them, and that it’s enough to have a lot of them. Nothing could be further from the truth. Poorly prepared tests can cause as many problems as poorly written production code.
For each of the postulates, the author gives examples. In the case of tests, he describes how running tests on different platforms can produce different results. This is because multi-threaded code works differently on different platforms.
Writing code without good planning is one of the most common mistakes. Well-written code, in general, cannot be created easily. It requires detailed planning and thinking.
If you can focus only on one attribute of the code that you write, it should be readability. This book will not only teach you how to write effective code that’s easy to read, it also contains excellent exercises in cleaning up dirty or failed code.
Start by guessing or designing your validations even before you write the code to satisfy them. TDD (Test-driven development) is not a bad idea.
“Clean Code” by Robert C. Martin is a valuable resource. I learned a lot of interesting things about writing effective, easy-to-understand code. Highly recommended!
Hi, I’m Adam Cudak, a .NET developer at Softensity.
I live in Kraków, Poland. Like every engineer, I try to constantly develop my knowledge in the field of IT innovations. Thank you for your time and if you have any questions – feel free to ask.