Writing code is like writing an article

Source: Internet
Author: User

In this book, Uncle Bob advocates "writing code is like writing an article" and says that "a master programmer uses the system as a story rather than a program to write it." I am very impressed with this idea! Before that, I have never heard of writing code as stories or articles. Uncle Bob is so talented!

  
How can we write clean code? The general principle is nothing more than KISS (Keep It Simple Stupid): to make the code Simple and direct, so that readers can easily see the intent of the designer. This book provides many methods and specifications that can help you write more clean code.

  
This is a good book. Give this book four stars, this is because this book is not as good as "refactoring-improving the design of existing code", describing code compilation, and describing code design as well as agile software development (Bob ). uncle's previous classic book ). In addition, the Chinese version has a high price and the translation quality is very general.

  
Reading Notes:
Chapter 1 clean code
1. Clean code strives to concentrate, and every function, every class, and every module is focused on one thing.
2. The clean code is simple and straightforward, and never hides the intent of the designer.
3. Clean code should have unit test and acceptance test. It uses meaningful names, and the code expresses meaning literally.
4. eliminate duplicate code and improve code expressiveness.
5. Keep the code clean and tidy.
  
Chapter 2 meaningful naming
1. Using a name that reflects the intention makes it easier to understand and modify the code.
2. programming is a kind of social activity.
3. Try to write easy-to-understand code
  
Chapter 3 Functions
1. A function should only do one thing (High Cohesion) without any side effects.
2. Read the code from top to bottom, as if reading newspapers and articles.
3. Long and descriptive function names are better than descriptive long comments.
4. Use less output parameters.
5. reject the boolean parameter.
Example: CopyUtil. copyToDB (isWorkDB) --> CopyUtil. copyToWorkDB (), CopyUtil. copyToLiveDB ()

6. Use exceptions instead of returning error codes to simplify the error handling code.
7. Writing code is like writing an article. First, you can write it as needed, and then polish it: break down the function, modify the name, and eliminate duplicates.
8. Programming is actually a language design art. Masters use program systems as stories. Use accurate, clear, and expressive code to help you tell stories.
  
Chapter 4 notes
1. Don't comment on bad code-rewrite it.
2. put effort into writing clearly understood code and directly ensure that no comments need to be written.
3. Good comments:
Legal information
Provide information
Interpreting intent
Alert
TODO comments
  
Chapter 5 format
1. The code format is very important. Code format is related to communication, and communication is a top priority for professional developers.
2. Learn code writing from newspaper formats.
  
Chapter 6 object and Data Structure
1. Only functions that operate data are provided after the object hides the data in the abstract.
The data structure exposes its data and does not provide meaningful functions.
2. The Law of Demeter: The module should not understand The internal details of The objects it operates on.
  
Chapter 7 Error Handling
1. Use an exception instead of an error code.
2. try-catch-finally: log error information.
3. Do not return null or pass null.
NULL Object Mode, for example, Collections. emptyList ();
  
Chapter 10
1. Top-Down principle: make the program read as a newspaper article.
2. The method can be protected for unit testing.
3. SRP: the class or module should have only one reason for modification. The class name should accurately describe its responsibilities. High Cohesion.
4. Open and closed principle OCP and dependency inversion principle DIP
5. variable name, method name, and class name are all ways to add comments to the code.
  
Chapter 1 iteration forward
1. tightly coupled code is difficult to write unit tests.
2. Unit Testing eliminates the fear of cracking the code by clearing the code.
3. It is easy to write codes that you can understand. The main cost of software projects lies in long-term maintenance.
4. The code should clearly express the intent of the author; the test code can serve as a document through an instance.
  
Chapter 2 gradual improvement
1. programming is a skill. To write clean code, you must first tolerate dirty code and then clean it up!
2. Writing good articles is a process of gradual improvement.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.