Clean Code - 1. Clean Code

[TOC]


Chapter 1. Clean Code - Main Takeaways

We want the reading of code to be easy, even if it makes the writing harder.

Quality vs. Business Pressure -> Managers may defend the schedule and requirements with passion; but that's their job. It's your job to defend the code with equal passion.

Memorize this analogy and use it frequently:

What if you were a doctor and had a patient who demanded that you stop all the silly hand-washing in preparation for surgery because it was taking too much time? Clearly the patient is the boss; and yet the doctor should absolutely refuse to comply. Why? Because the doctor knows more than the patient about the risks of disease and infection. It would be unprofessional (never mind criminal) for the doctor to comply with the patient.


Quality vs. Business Pressure

In the Chapter 1 I found an inspiring and powerful analogy for when I think about "how to encourage people to care about quality, despite business pressure":

what if you were a doctor and had a patient who demanded that you stop all the silly hand-washing in preparation for surgery because it was taking too much time? Clearly the patient is the boss; and yet the doctor should absolutely refuse to comply. Why? Because the doctor knows more than the patient about the risks of disease and infection. It would be unprofessional (never mind criminal) for the doctor to comply with the patient.

It somehow made remember the Regra 02 - Cuide de si mesmo como cuidaria de alguém sob sua responsabilidade, where Jordan Peterson says that we are more susceptible to external pressure (a doctor being unprofessional can be considered a crime) than internal motivation (a doctor just wanting to be "professional").

Another good thing to keep in mind is that:

[managers] may defend the schedule and requirements with passion; but that's their job. It's your job to defend the code with equal passion.

Reading vs. Writing

We want the reading of code to be easy, even if it makes the writing harder.

We read code much more than we write. In fact there's no way to write code without reading code.

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.

Because this ratio is so high, we want the reading of code to be easy, even if it makes the writing harder. Of course there's no way to write code without reading it, so making it easy to read actually makes it easier to write.

(...) if you want your code to be easy to write, make it easy to read.

The Boy Scout Rule

Leave the campground cleaner than you found it.

Replace campground with code above. 🙂


http://on-agile.blogspot.com/2007/04/why-you-wont-fix-it-later.html