Learning to read codebase

Hi. So recently i'm trying to teach myself to learn from reading existing codebase in rust. It will allow me deepen my knowledge even more because i will stop relying on somebody else's help to learn something.

My problem with this is that very often library does a lot of things and it's really hard to understand something after entry point. My attempts were just step debugging some basic functionality, but i couldn't go further because some features always not so popular as others. Some crates are really fragmented like smol, that i was suggested to try. And some are really really big like async-std and tokio.

Also i have a problem that i want to learn ALL at once, but it's obviously not possible and I can't really pickup independent enough feature to start from there

How would you suggest me to start this?

  • Pick a topic you're already familiar with and look for packages related to it.
  • Ideally, build a small application using the package you want to study.
  • Take a top-down approach: First, skim through the code to get a general sense of its structure, then dive into specific details.
  • Focus on a concrete example, analyze what the code is doing in that specific case.
  • If a package doesn’t click with you, move on to another one, there are plenty to choose from.
  • Old-school method: Print out relevant parts of the code, grab some colored markers and a pen, and annotate freely. Highlight key sections, draw connections, and go wild!
  • Accept that, in the beginning, you’ll only understand small parts, this is normal.
  • Keep at it. Do it often, consistently. Don’t give up, no pain, no gain!
4 Likes
  • Pick something you are interested in.
  • Find a popular crate that does that thing you are interested in.
    You will learn how to navigate crates.io, libs.rs, docs.rs, and github.
  • Download the source for that crate.
    You will learn how to use "git"
  • Look in the examples directory.
  • Get a small example to compile.
    You will learn how to use "cargo"
  • Read the example and try to understand it.
  • Edit the example to make it do something else.
    You will learn the nuances of your editor and rust-analyzer.
  • Recompile the example.
    You will learn how to read error messages.
  • Ask in this forum how to solve your error. (if you get stuck)
1 Like

Large codebases exist by being modular, so you don't have to understand the whole thing to work on one specific part. There's a lot of tricks for navigating large codebases.

One trick is looking for the fixed part of error messages. For example, if you get an error identifier not found: "foobar", you could search the codebase for "identifer not found" to see where it's emitted, then walk the control flow graph from there.

2 Likes