Tools to help me learn a big codebase

This questions is about tools that will enable me to learn a big code base.

I have always worked on my own and without any collaborators. It has meant that I’ve never had to learn the source of a code base written by someone else. I expect this is a typical challenge for professional programmers, and that several techniques and tools exist to get an overview and navigate a big code in a way that is conducive for learning it. Typical problems I face are:

  • If a function calls a number of other functions, which way can I piece together what it does? In particular when there are a dozen different definition of each function (because there are different input types) scattered all over the place, how can I find the the one that is relevant for a specific input type?
  • If I don’t understand the types, and which is a subtype of what, how can I quickly get an overview of the hierarchy?

What are the necessary and sufficient tools that I will use to do this effectively?

3 Likes

For the first, Cthulhu.jl is really good. It is like @edit but gives you a repl that lets you explore the entire call graph (as well as track down performance issues like type instabilities).

6 Likes
1 Like

I would recommend using debugging to work out what code does, as you can track the value of variables as it executes and go as deep/shallow as you like.

Start with finding an example in the docs of common usage and then use @enter before calling a function (available in VS code Julia REPL) and you can use step in, over or out to navigate through the code:

using ExternalPackage
@enter external_func(1234)

If the other code also has unit tests, they can be a good way to understand what the code is supposed to do. You can copy a unit test into a file and also debug through this code too.

2 Likes

This is a good way of looking at the codebase graph: FinEtools.jl/diagram.svg at main · PetrKryslUCSD/FinEtools.jl · GitHub

It can be generated with a workflow described here: GitHub - githubocto/repo-visualizer

1 Like