/ Learn

[Clean Code] Some thoughts about Clean Code ?

In this series of posts , I would try to share with you some of my highlights on Clean Code Chapters.

In this post my focus would be on chapter 1.

We can define Clean code as code that 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++

Beck’s rules of simple code.

In priority order, simple code:
• Runs all the tests

• Contains no duplication

• Expresses all the design ideas that are in the
system

• Minimizes the number of entities such as classes,
methods, functions, and the like.

What causes duplication ?

When the same thing is done over and over, it’s a sign that there is an idea in our mind that is not well represented in the code. We should try to figure out what it is. Then try to express that idea more clearly.

Clean code can be read, and enhanced by a developer other than its original author. It has unit and acceptance tests. It has meaningful
names. It provides one way rather than many ways for doing one thing. It has minimal dependencies, which are explicitly defined, and providess clear and minimal API. Code should be literate since depending on the language, not all necessary information can be expressed clearly in code alone. , Dave Thomas ,the god father of eclipse

Final Note

The @author field of a Javadoc tells us who we are. We are authors. And one thing about authors is that they have readers. Indeed, authors are responsible for communicating well with their readers. The next time you write a line of code, remember you are an author, writing for readers who will judge your effort.

The ratio of time spent reading vs. writing is well over 10:1.
We are constantly reading old code as part of the effort to write new code.

The code you are trying to write today will be hard or easy to write
depending on how hard or easy the surrounding code is to read. So if you want to go fast, if you want to get done quickly, if you want your code to be easy to write, make it easy to read. Make it a clean code.