When manually inspecting unfamiliar code (to review or modify), I seem to have three options.
- A top-down read of the code, choosing each next source file by how fundamental the filename seems. I usually end up reading nearly everything. Some files twice.
- A breadth-first read, where I find and read all of the invoking method with minimal understanding. Then read all the functions that function called, and so on. My mental stack tends to overflow if I make it a few calls deep.
- A depth-first read, where I step through all the code in a debugger, unsure of whether this will take 8 minutes or 8 hours.
Once I've read enough of the code to have a fairly solid understanding of what it's doing, I often reflect that I've read 80% or more of the codebase, while the fundamental code is 20% or less. I've wasted a lot of time.
What tools are useful for getting a quick grasp of unfamilar code? Are there any tools that can give a "big picture" of the critical code path and allow me to drill down to the details of any one part?