★★★ ★✰
An overview of the
What if there were four simple rules to follow that could help you create great design?
The practices described in this chapter are distilled from decades of experience by the authors of the original book.
Run all tests
The first rule is that the system must be designed to work as intended. A system may have an excellent design, but without an easy way to verify that the system actually works as intended, it will be useless.
Two, not repeatable
The common code extraction, “small-scale reuse” can greatly reduce system complexity. To achieve large-scale reuse, you must understand how to achieve small-scale reuse.
function size() {}
function isEmpty() {}
Copy the code
function isEmpty() {
return 0 === size()
}
Copy the code
Third, expression
The main cost of a software project is long-term updates and maintenance. Therefore, the code should clearly express the intent of its author. The clearer the author makes the code, the less time others have to spend understanding it, reducing defects and maintenance costs.
- Good name
- You divide a big function into smaller functions
- Resolution of the module
Have as few classes and methods as possible
And finally, of course, too much of a good thing. Even basic concepts like eliminating duplication, code expressiveness, and SRP (Single responsibility Principle) can be overused. All principles should be practical and not subject to meaningless dogmatism.
This article is based on Code Cleanliness by Robert C. Martin, translated by Han Lei.
Zhejiang Dahua Technology Co., Ltd.- Soft research – Smart City Product R&D Department Recruiting senior front end, welcome to contact, interested can send resume to [email protected], long-term effective
11. System
Concurrent programming