❓ What is Clean Code?

As @unclebobmartin says in the Clean Code book: there are probably as many definitions of Clean Code as there are programmers.

This is a thread 🧵 about what I believe Clean Code is.
First, my favorite quote from a well-known author:

"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.
In my own words ...

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.
2⃣ 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.
3⃣ 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.
4⃣ 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)'
5⃣ 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.
6⃣ Clean Code does not smell.

🔹It is not rigid. It is easy to change.
🔹It is not immobile. You can reuse it easily.
🔹It is not opaque. It is easy to understand its intent.
🔹It is not fragile. You can change it without introducing unintended bugs.
7⃣ 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.

➡️ The only way to go fast is to go well ( @unclebobmartin).
📢 A call for software companies:

Stop looking for experts in paint brushes. Find good artists.

Focus your effort in finding software engineers that can write Clean Code.
You can follow @macerub.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: