Author: [us] Robert C. Martin Douban score: 8.6
Code cleanliness is a basic professional ethics.
Do people have to put themselves in place and write code? Will it not leave any trouble for later users? I cannot answer this question.
This book is a useful tool for reflecting on yourself and specifying the path to writing code: good name, clear functions, and no messy functions.
Chapter 2 Name
Select a good name for the code son: The variable name is not a good name if it needs to be noted.
Avoid misleading: O0l1? I cannot tell you clearly. Keep yourself up and don't bother yourself or others.
The name that can be read. What is the difference between genymdhms and genymdhms? What is the name. GetAccount getAccounts getAccountInfo, which one should be used?
Searchable name: a constant refers to the meaning of magic number and can quickly find out where it is used.
Class Name is a noun; method name is a verb or verb phrase. Use a universal name.
Thank you! Taking care of what you create is the most precious resource.
Chapter 3 Functions
A good function is a short function: each function only says one thing, and then takes you to the next function in sequence. The code block in if else while should have only one row. Good functions are at different abstract levels and can be read from top to bottom. The related functions are put together, and the previous guidance points to the next one. Remove try catch to avoid disturbing the code structure.
A master programmer uses the system as a story rather than a program.
Chapter 4 notes
Good comments: legal information, explanation intention, and warning. Do not write redundant comments, and do not write terrible nonsense. The commented-out code is scum and must be deleted!
Chapter 5 format
Learn to typeset from newspapers.
Chapter 7 Error Handling
Error handling is very important, but if it disrupts the code logic, it is an error. The most important consideration for defining exceptions is how they are captured. Packaging exception. Only one type of exception is output to the outside world. Do not return or pass a null value. Return an empty object such as Collections. emptyList () to keep the code clean.
Chapter 4 boundaries and tests
Learning Test to learn about third-party components. Keep the test clean. The test code is as important as the production code. First Principles: Fast, Independent, Repeatable, Self-Validating, and Timely.
Chapter 10 short categories
Single responsibility; class should be small enough;
Chapter 2 System
It was a myth to do the right thing in the first place. Instead, we should only implement today's user stories. Internet user groups may surge, or there may be no users at all. It is important to do a good job of resizing.
Software systems are similar to towns and cities, and similar physical systems can all increase progressively. Proper splitting is required.
Chapter 2 concurrency
Why concurrency: break down the objective and timing to improve the system throughput and structure.
Execution model
Basic definition: limits resources, mutex, thread hunger, deadlocks, and live locks.
Basic Model: producer-consumer model, reader-author model, banquet philosopher model. Keep the synchronization area small. Do not blame system errors for accidental events: cosmic rays, hardware problems, and so on. First, make non-thread code run.
Chapter 2 gradual improvement
To write clean code, you must first write dirty code and then clean it up. Most new users write programs that can work and move them to the next task. The programs that can work can only work. This is a self-destruction.