Clean Code

#books/tech


Main takeaways

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.


Chapter 2. Meaningful Names Main Takeaways

  • use intention revealing names
  • avoid disinformation
  • make meaningful distinctions
  • use pronounceable names
  • use searchable names
  • pick one word per concept
    • choose between get/fetch/retrieve)
  • use solution domain names
  • use problem domain names
  • add meaningful context
    • addressState is better than state
  • don't add gratuitous context

Chapter 3. Functions - Main Takeaways

Some rules for functions:

  • Small
  • Do one thing
  • One level of abstraction per function
  • Read code from top to bottom
  • Use descriptive names
  • Use as less arguments as you can (ideally zero)
  • Have no side effects

Anything that forces you to check the function signature is equivalent to a double-take. It's a cognitive break and should be avoided.


https://github.com/JuanCrg90/Clean-Code-Notes