Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you have access to a whiteboard...

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.



I usually end up doing this, but not formally. I dive into the code and eventually find the bottom, and then work up. In the future, I think I'm going to try this and avoid wasting time wandering about trying to keep track mentally of everything as I go along. At the very least, I'll write it out in a notebook.


Thanks for the answer! It sounds like you're taking a bottom-up approach when reading code. Do you think we can use software to build this dependency graph and make it easier to read code?


Yes, technically it is possible. Some languages (and build tools) are a lot easier than others.

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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: