Contents

Clean Code

Contents

There are probably as many definitions of Clean Code as there are programmers.

“Clean Code reads like well-written prose” - Grady Booch

A short sentence that says it all.

Clean Code should be as enjoyable as reading a good novel. Names are revealing. Flow is simple. Clean Code tells a story.

  1. Clean Code is like a good painting.

When you look at a good painting, you know it’s good, even if you are not an artist.

Clean Code feels the same. It’s a pleasure to read. It’s orderly and elegant. Everything is there for a reason.

It makes you smile.

  1. Clean code is simple.

It is so simple that the author does not look smart. And yet, it is obvious that the code was written by someone who put effort in it.

Simple is not easy.

Clean code always looks like it’s been written by someone who is passionate about their craft.

  1. Clean code is focused.

It does one thing and it does it well, in a few words.

Intent is clear. There are no ambiguities. It doesn’t have surprises and unintended side effects.

If you invoke “fillComboBox”, you know that the method will not inadvertently modify a file.

  1. Clean Code speaks about the problem, not the solution.

It tells the story of the problem being solved. It’s at the right level of abstraction. It uses a minimal amount of “computerish” terms.

'print(inputRecord)'

'sendPromotionLetterTo(employee)'

  1. Clean Code pays close attention to details.

Error codes are meaningful.

Error handling is explicit.

Variable and function names are consistent.

There are no memory leaks.

There are no tricky constructs.

Abstractions are expressive and useful

  1. Clean Code does not smell.

Small blue diamondIt is not rigid. It is easy to change. Small blue diamondIt is not immobile. You can reuse it easily. Small blue diamondIt is not opaque. It is easy to understand its intent. Small blue diamondIt is not fragile. You can change it without introducing unintended bugs.

  1. Clean code is covered by a comprehensive and meaningful suite of tests.

No matter how clean the code is today. If it has no tests, you cannot refactor it confidently. This means that the code will become unclean, eventually.

But, why would you want your code to be clean?

Code is read far more times than it is written.

Favoring a solution or technique that makes writing fast at the expense of readability does not make sense.