I recently bought several classic programming books, including head first design model, Man-Month myth, programmer cultivation, and code Daquan. code Daquan is the second book.
During the reading period, I was constantly enlightened, and I was surprised by many places in the book, "it turned out to be like this 」. However, due to the limited time in my spare time, this book was nearly two months old. Now, I just wrote down what I realized with my impressions, which is a summary.
If I want to summarize code Daquan in one sentence, I think it is "writing code for people, not machines 」.
I. For code writing, it is necessary to consider the scalability of the code. People are changing, and the real world is also changing. Therefore, before writing code, you need to design a model so that you can change it if you want.
2. Easy coding for human code. The book emphasizes the importance of variable names countless times. It is also code, int I = 5 and int beautifulGirlsCount = 5, although both types of code can be correctly compiled and run, however, the former may not be correctly understood based on the context, and the latter may be clear at a glance.
3. Writing code for humans is bound to consider whether the logic of the code is simple. In front of machines, human intelligence seems too limited. If the code does not follow simple logic that humans can understand, such as if, for, and switch, use goto and recursion without restrictions. When the amount of code reaches a certain level, people cannot maintain such a program.
4. When writing code for humans, exceptions are inevitable. From the beginning, Jack Ma warned us that we should treat your users as demons. The devil will not use our programs as we imagined. The defensive programming in this book also reiterated this. People will make mistakes. Without a doubt, what is important is how to throw exceptions after mistakes, control the impact scope and remedy of errors.
5. Write code for people. It is necessary to write the code beautifully. You can see the articles printed in the book. All the texts are separated by punctuation marks. There is a gap between the line and the line, segmentation, and the layout of these articles should also be included in the code. Indentation, blank lines, and segments in the code not only make the code look logical, but also aesthetic. Therefore, formatting is very important. Even if your code is logically written, it is difficult for others to endure it.
The summary of these points obviously cannot cover more than eight hundred pages of "code Daquan". However, for me who just walked on the code Farm Road, I have been able to digest it for a while. In the real world, it is even more difficult to do so. During the reading of this book, I watched the code left by my predecessors every day in the company during the day. I don't know what mActivity is, and the system crashed everywhere, I know that reality is as skinny as I do. However, the fullness of the ideal is the same as the plump beauty, will not suddenly hit me from the sky. Good code is produced one by one, and beautiful women seduce each other step by step. There is no shortcut here.
After reading code Daquan