Summary of — Clean Code by Robert C Martin —Part 1: Overview
First of all, I want to thank this marvelous author who did countless research and interviews to write this important book. It has definitely changed my way of thinking and programming. If you really want to understand fully about clean code, I recommend you to buy this book from Amazon.
This series of articles is intended to give a high-level idea to our fellow developer community on how together we can write a better code for the next generation.
Why Clean Code?
Programming in an existing codebase is not easy. We all have been in a situation where our productivity was slowed down because of a messy existing code. Have you ever went through a phase where instead of one line change, you were made to change hundreds of different modules?
I personally have felt the need for good code when debugging what could have been done in 5 mins, instead took 3 hours of my crucial time.
Programmers face a problem of basic values. All developers with more than a few years of experience know that previous messes slow them down. And yet all developers feel the pressure to make messes in order to meet deadlines. In short, they don’t take the time to go fast! True professionals know that the second part of the problem is wrong. You will not make the deadline by making a mess. Indeed the mess will slow you down instantly and will force you to miss the deadline. The only way to go fast is to keep the code as clean as possible at all times.
What is clean code?
Here are a few definitions by some very well-known and experienced programmers. All definitions emphasize better readability, maintainability, robust and ease to test. But the one I liked the most is — Clean code always looks like it was written by someone who cares.
I like my code to be elegant and efficient. The logic should be straightforward to make it hard for bugs to hide, the dependencies minimal to ease maintenance, error handling complete according to an articulated strategy, and performance close to optimal so as not to tempt people to make the code messy with unprincipled optimizations. Clean code does one thing well.
~ Bjarne Stroustrup, Inventor of C++
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, author of Object Oriented Analysis and Design with Applications
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 Feathers, author of Working Effectively with Legacy Code
You know you are working on clean code when each routine you read turns out to be pretty much what you expected. You can call it beautiful code when the code also makes it look like the language was made for the problem.
~ Ward Cunningham, inventor of Wiki
The art of writing a clean code
The most basic need is you must know what it means for a code to be clean. Most of us can differentiate between a good painting and a bad painting but it does not mean that we know how to paint. Similarly, knowing the difference between clean code and dirty code does not mean you know how to write clean code.
Writing clean code requires the disciplined use of countless little techniques applied through a painstakingly acquired sense of “cleanliness”.
Please read my next article — Summary of — Clean Code by Robert C Martin — Part 2: Meaningful Names — to understand how to choose meaningful names in your code.