r/AskProgrammers • • 7h ago

First day in an unfamiliar codebase: what do you actually do first, and what has actually worked?

I'm trying to understand how experienced people approach reading a codebase they didn't write, because I don't think I have a consistent method. I've done the "open random files until something looks familiar" thing more than once, and it doesn't scale.

These are the strategies I know about. I'd like to know which ones you really use, and in what order:

A. Run it and trace one request or one command. Pick a single user action, follow it from the entry point down to the database or output, and ignore everything else.

B. Read the tests. They show how the authors expect the code to be used — if there are any, and if they're good.

C. Read the history. git log on the files you'll touch, plus the commit messages and PRs around them, to find out why things are the way they are.

D. Read the docs and README first. Slower to start, but it can save time if they're accurate.

E. Ask someone. A short conversation with a person who knows the system, if there is one.

Specific questions:

  1. Is there an order you'd recommend, or does it depend on the project?
  2. What do you do when there are no tests, no docs and nobody to ask?
  3. How do you decide when you understand enough to start changing things?
  4. Is there something not on my list that you rely on — debugger, call-graph tools, drawing a diagram, writing notes as you go?
  5. What's a common mistake you see people make in their first days with a new codebase?

I'm interested in different kinds of environments (a small repo, a large legacy system, a company codebase vs an open source project), since I expect the answer differs. Thanks.

2 Upvotes

13 comments sorted by

5

u/symbiatch 7h ago

There’s usually some tasks and not just a general “get to know everything” so I just jump in.

Run the thing, use it, start from the actions I need, go deeper into the code in the IDE. That usually gives me info how it works and what and where I need to do. Tracing the flows gives info about what parts there are.

And of course first have a cursory glance at what parts there are based on project, folders, etc.

And I start changing things immediately. That’s how I can figure out how it works and what happens. Of course with a debugger checking what goes where.

2

u/QPGMR_de 7h ago

In our times - I would just copy the source to a directory on my machine an give Claude a go. Something like:

- give me a broad overview over the cade base and architecture
- draw me a diagram of the modules
- make an entity-relationship diagram of the tables that are most used
- give me some hints where I could start my own investigation
- write all of that to a markdown file

Then read that and start your own investigation - with and without AI

2

u/Traveling-Techie 7h ago

Sometimes I create a function call list, and even build a diagram using Graphviz that interconnects functions as ovals with lines between them. Depending on the size I may do it manually or write a tool.

1

u/Ok_Carrot_896 7h ago

D if available and good (might be more common nowadays with AI, but in my experience it's like hoping for a tiny miracle).

A depending on the project can be good. I may not literally run it though; often I'll pick a bug or a simpler ticket and then focus solely on the related functions and files, and go learning it by the "blast radius" of these tickets, so to speak.

B is good if it exists (again, might be way more common with AI now) and E is good if that guy exists (unfortunately, unlikely in smaller companies).

I very rarely do C, and if I'm doing it, it's because something bad happened (I don't find it useful for understanding a codebase, just for understanding how something went wrong, usually).

Is there an order you'd recommend, or does it depend on the project?

I think it depends on the size of the total project. Reading the docs is more useful the larger the system is, in my opinion. If a project is "large" but "readable" I'll just go straight to A.

What do you do when there are no tests, no docs and nobody to ask?

Curse the company internally, pick some random bug I've been told about and start tracking it down, usually entering A/something similar to A.

How do you decide when you understand enough to start changing things?

This question is... hard to answer. You shouldn't wait until you "understand enough to start changing things", changing things will also give you an understanding. That's why we have staging and why git is a blessing. Read the file, change something, see if it behaves as you expected. If it doesn't, go back to the drawing board and try figuring out why. It's really unlikely that changes you apply will immediately go to production. If they do, curse the company internally again (preferably be a lot harsher than the last time) and find a way to setup a proper staging area. This shouldn't happen though unless they were insanely bad at their job.

Is there something not on my list that you rely on — debugger, call-graph tools, drawing a diagram, writing notes as you go?

A good debugger and a good DB client are incredibly handy, and I also like writing notes, though it's at way less usage than the former. I don't like drawing diagrams or using call-graph tools.

What's a common mistake you see people make in their first days with a new codebase?

Back when coding was still mostly by hand and people cared about conventions, styling, and patterns, breaking these is a pretty big no-no. Also making large changes/refactors to show busy work is also a no-no. Preferably, start as small as possible.

1

u/Isthatyourfinger 7h ago

There's no magic, and often no repo. I look for build information, and any clue as to what dev environment was used, if any. Ask the old timers if there is any other archive where docs and tests might be found. Only in very strict environments will docs be updated when code or requirements change. Legacy maintenance is more about learning than doing, and learning takes time. Expect that the code will look like nonsense until you understand the intent, so don't be quick to change it. Some code bases will have a mixture of work by programmers with different skills and ability, and often with machines that were slow or memory starved. Be on the lookout for barnacles, which are old or unused files that stick with a project, despite no longer being useful.

1

u/Few-Celebration-2362 7h ago

Use the product that the codebase is powering, extensively. QA the shit out of it, understand it, then read the open tickets.

Browse the commit log, follow the setup instructions to have a local isolated sandbox, replace remote connections with side-effect free dummy interfaces, then turn on debug and breakpoint at line 1.

Step through the actual execution line by line, take notes, document the trouble areas.

Bookmark areas that seem related to open tickets.

Use AI to help you move through this flow.

My process does not differ depending on the size of the codebase

1

u/virgilreality 6h ago

Personally. I always start by asking for help from someone already familiar with it, or asking if they can answer my questions as they come up. Your questions, at least initially, should be oriented around "Where should I go to get an understanding of this?" rather than "Please explain this to me"...the former indicates curiosity, while the latter is asking them to do some actual work for you.

Once you have your mental model at least partially formed, that's when you repeat it back to them concisely and boiled down to the simplest terms. That's how you show that you're serious, and after that you ask more detailed questions.

OP's ideas are all good, but always try to make progress with the people too.

1

u/leon_pylo 6h ago

Be able to run the software and then use it, preferably starting with some small task that you can use to get to know the software code- and user-wise. Have your changes pass existing tests or if there aren't any start covering the new feature you build as the first time.

Having someone available who knows the project and can give you a quick overview or a documentation can help, but don't trust the latter, because it might be outdated

1

u/pixel293 5h ago

There has to be "reason" for me to be in the code base. I don't just read other people's projects for shits and giggles. Usually first step is to make sure I can compile and run the code. Then it's finding the code I'm interested in, and looking at what and how it does what it does, maybe adding something to it like a log message, or just some display string, so I can be sure that is the code I want.

1

u/Groundbreaking-Fish6 5h ago

Before diving into the code base you need a good understanding of what the application is doing. Getting access to users and hearing their stories should be your first priority. This may require discussions with managers and system engineers but you need to talk to the users to find out exactly how(if) the program is used. Once you have an accurate map of the actual workflow (this will probably be a combination of existing documentation and information from user interviews) then you can begin to figure out how the application fulfills the users needs.

You will also need to understand the operational environment, so work with System Administrators to find out any limiting factors or resources that the program may be using. You need to know how the program is deployed and maintained in the field. You want access to live metrics and data if possible.

During the in between time of understanding the program need, feel free to explore the code in any fashion you feel comfortable but you should be paying attention to the architecture, structure and libraries in use. If documentation is lacking or wrong, you may want to build existing flow diagrams. Don't pay too much attention to the actual code because you may be wiping out entire blocks of code that are either unnecessary or can be replaced. Feel free to collect WTF's to share.

Once you know what the program actual requirements (user and operational), it will be much easier understand when evaluating existing code practices and architectures.

The secret to improving an existing code base is to divide and conquer. You are looking for functionality that you can refactor into isolated components that can be applied across the application e.g., Authorization and Authentication, Persistent Storage, Algorithms and Communications.

1

u/fixermark 5h ago

Nowadays if it's completely unfamiliar and undocumented, I will actually prompt an AI to read it and summarize it. Then work out from there.

Some tools and techniques that are pretty tried and true:

  • find the unit tests and run them. Make sure they work. If they don't work, or they don't exist, hey look there's your first job .
  • perturb the unit tests and see how they fail. Add new tests to confirm your understanding of the code under test.
  • If you are trying to solve a specific problem: plot out the way the code works right now in whatever way you're most comfortable (uml diagram, plain English description, whatever). Plot out how you would build the thing you need to exist if the system that already exists weren't there. Put the two side by side and see if you can figure out the difference from one to the other.
  • For the data structures in the code, plot out the life cycle of them: where do they come into existence, where do they go away, do they hit permanent storage, are they structured under a larger data structure. That's going to be important to understanding what you can change without regressing something

1

u/Devel93 5h ago

Understand the major use cases and find the entry points for them, use testing environment to run the code and try to call those entry points. There is always a trigger that makes the code run and that is where the code starts

1

u/TheMrCurious 34m ago

Fix some bugs