Stop writing legacy Code – What’s Clean Code

Clean and dirty

If you want to stop writing legacy code we have seen the importance of doing TDD, because it let’s you refactor your code and improve it. Well, actually refactoring lets you change your code, modify it. To actually improve it you need to change it in a positive way, with a better structure. You need to know how to improve it. That’s why in the following blog posts will talk about some guidelines to clean our code.

The father of Clean Code is Robert C. Martin (or Uncle Bob), he has written a number of great books that I suggest you read. A great deal of what will talk about comes straight from the book Clean Code: A Handbook of Agile Software Craftsmanship that in my opinion is the bible  in this matter. Another important book is Code Complete: A Practical Handbook of Software Construction by Steve McConnell.

We will first have a look at names and how to choose them in a way guides us through the code, than we’ll talk about functions how big (or small) they should be, then how to (not) write comments and some guidelines for your classes. Finally after we have clean production code we will explore the importance of having also clean test.

But what does it mean to write Clean Code. It means writing code that is easy to reason about. When you first approach it, or when you navigate in it you should feel like you know it. The names should guide you, and every function should turn up to be pretty much what you expected.

Working on clean code is a great experience and since you are the one writing code… why not write it clean?

Author: Maurizio Pozzobon

Maurizio has 5+ years developing solutions in the insurance industry. He is passionate about doing the right thing right, so he works in a tight loop with his clients to deliver the best solution possible.