How to read code correctly

1. The way to learn to write great code is to read code, read a lot of code; high-quality code, low-quality code; assembly language code, Haskell code; code written by strangers thousands of miles away; and our own last week Code just written. There is probably no great novelist who has never read someone else's work, no great painter who has never studied someone else's painting, and no skilled surgeon who has never watched a colleague operate.
2. However, we expect programmers to be able to write good code without reading other people's code...
3. Code reading is full of fun. Read code to learn tricks and analyze pitfalls. Delight in the deft structure and unexpected symmetry.

4. When reading code, ask yourself questions, such as: Why do you write this way? Or something in the author's background that made him/her make this choice?
5. Reading actual, well-written code can provide a deeper understanding of how to construct and write important systems than just writing small programs.
6. When I read the source code, I just read it. Have I commented and improved the code? And can you learn a lot from it?
7. Make a habit of spending time reading high-quality code written by others. Just as reading high-quality prose enriches vocabulary, stimulates imagination, and expands thinking, analyzing the internal structure of a well-designed software system can learn new architectural patterns, data structures, programming methods, algorithms, styles, and documentation specifications, applications Program programming interfaces (APIs), and even new computer languages. Reading high-quality code can also improve the quality of your code.
8. Read the code selectively, and at the same time, have your own goals. Do you want to learn a new pattern, coding style, or a way to meet certain needs?
9. Be careful to start reading with small programs; don't immediately get caught up in the study of large systems. Compiling the researched programs and running them, so you get immediate feedback on how the code is supposed to work, and a sense of accomplishment, the next step is to proactively modify the code to verify that the understanding of the code is correct. Again, start with small changes and gradually increase their scope.
10. Another way to actively read existing code is to improve it.
11. Be prepared to use a number of different strategies and approaches to understand how the code works. To get started, read as much documentation as you can find. Ideally, official software design documentation can be found, but even user documentation can be helpful. Practically use the system and learn about its external interfaces. Be clear about what you are looking for, is it a system call, an algorithm, a sequence of code, or an architecture? Design a strategy for discovering object code.

From: huawei_d's blog

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325810752&siteId=291194637