What's the best way to read and understand someone else's code?

2023-05-16,,

    Find one thing you know the code does, and trace those actions backward, starting at the end

    Say, for example, you know that the code you're viewing ultimately creates a file with a list of movie titles. Figure out where in the code - the specific, few lines - it generates that file.

    Then, move one step backward and figure out how it places the info in the file.

    Them, move another step backward and figure out where the info came from

how the body of code is organized(where variables are defined, where different types of functions are located, etc)

the person's style of coding

how the person who wrote the code thinks and problem solves

[ a big file of code that doesn't really mean much at all to you ]

you'll now be looking at:

[ still a big file of code, but where you now understank a few specific sections ]

using "chains of actions" to gradually understand a never-before-seen piece of code

    Rinse and repeat

    Repeat that process multiple times, and you'll rapidly increase your understanding of more and more pieces of the overall codebase

    The reason that works well is that, in all cases, a body of code is designed to tackle one or more complex problems. So you'll always have those "chains of actions" throughout

    And the more you can gain an understanding of how different parts of the code are connected, the more you'll develop an understanding of the entire codebase

    The more good code you see, the easier it becomes to read and understand all code, and the faster you cando so

    The more you watch to expert examples, the better you can become. The less exposure you have to experts or result of expert workm the less likely you are to develope expert skills

     

What's the best way to read and understand someone else's code?的相关教程结束。

《What's the best way to read and understand someone else's code?.doc》

下载本文的Word格式文档,以方便收藏与打印。