Ask HN: How do you read code? Given a new project or an unfamiliar codebase, how do you go about reading and understanding the code? |
Ask HN: How do you read code? Given a new project or an unfamiliar codebase, how do you go about reading and understanding the code? |
List all of the directories (or classes, for a smaller project), and draw them as boxes on the board.
Draw arrows between the boxes based on dependencies in the codebase (helps if you have someone already familiar).
... Now start at the bottom of the dependency graph, and browse the code at a medium level.
If you are going to be working in this codebase, go back through and browse the code at deeper level, as if you were doing a code review. You can pretty much assume that, every couple lines, there is always something you would change about the code. Make a note of it.
At this point, you should have a fairly decent idea of how the code works, and how you would change it.
For purposes of learning the code, it may not be worth automating the dependency graph. You will probably learn more from tracking it down than you would if it was pre-generated for you.