Live data from Hacker News

Ask HN: What are the ways you go about getting comfortable with a new codebase?

news.ycombinator.com

21–30 of 69 posts

Re: Ask HN: What are the ways you go about getting comfortable with a new codebase?

#21
I like to focus on the main business element. If it's a SaaS for sharing videos with comments, for instance, I'd take a longer look at the video and comment models, their relations, and the call chain from API endpoint to model.

Another strategy I like is picking parts of the codebase and trying to refactor them. You don't even need to commit anything if you're not supposed to go around changing things: just by spending some time moving things around, seeing what breaks and so on will give you a better understanding of the code and what it does.

Re: Ask HN: What are the ways you go about getting comfortable with a new codebase?

#22
Refactor something unimportant with tests and a functional change, improve the documentation in the README, and push straight to the repo without a feature branch.

Reading the codebase does surprisingly little for me, you essentially have to change it and see what happens.

Re: Ask HN: What are the ways you go about getting comfortable with a new codebase?

#23
Three ways...

1. I go straight to the entry point, the main(), and then follow how the initial configuration, flow of data, sanitisation, and routing is done.

2. I look for bugs. Fixing bugs reveals the complexity as you need to look for side effects of the fixes when you don't yet know the system. Writing tests for those fixes also helps understand the system.

3. I look for the least changed part. I find these are usually the oldest and most core part of how the program works, whereas more recent changes are business logic and feature addition.

But of these, the first yield the greatest initial understanding and allows me to change things with less fear.

Re: Ask HN: What are the ways you go about getting comfortable with a new codebase?

#24
The best way is probably to make changes to it because that forces you to really understand the code. If you just read it without making changes it's too easy to pretend that you understand it. If there is one part of the code that you are trying to understand, I can recommend to write a replacement for it; then you at least learn how it works and you might even get a better solution.

Re: Ask HN: What are the ways you go about getting comfortable with a new codebase?

#25
Two things - First - I learn how the data flows from the source to the end. That teaches me to navigate the codebase entirely. (User action to database, or source data to end data etc.

Second - I learn how different components are wired together.

Re: Ask HN: What are the ways you go about getting comfortable with a new codebase?

#27
Try to profile the code and see where it's spending time.

Get a good flame graph up, and you'll have a really solid visual representation of what's going on.

Bonus: on almost any project, nobody has done a profiling pass in at least a few months, so you'll probably discover some extremely easy performance improvements and you'll look like a goddamn hero when you speed up e.g. the test suite by a factor of 3 in your first week on the job.

Re: Ask HN: What are the ways you go about getting comfortable with a new codebase?

#28
It's counterintuitive, but stepping through a very complex codebase with a debugger and taking notes along the way was great in my case.

Also, attempting to draw a sequence diagram and fixing it as you go trains the brain to handle a mental model of a large process.

Re: Ask HN: What are the ways you go about getting comfortable with a new codebase?

#29
Apart from reading, and trying to understand the architecture, these are some things you can do:

1. Fix a couple of bugs

2. Add a small feature

3. Refactor a small piece of it

Always start with few small things and keep increasing the complexity of the things you do. Working on a codebase is the best way to understand it.

Post reply on HN