Participating in open source has been awesome for me. It has made me and the stuff I make better. A common question that I get from folks is how to go about learning an open source codebase and understand other’s code.
In my blog post “Open Source Stamina”, I make an important observation:
You contribute best to something you use regularly.
So while it can be a lot of fun to just jump into any open source project and help out. Sustainable contributions are best found in projects that you use on a regular basis. You have a better understanding of the use cases of the code which will help you understand the code better.
Here’s a sequence of events I go through when I’m trying to learn or contribute to an open source project:
Look at the contributing guidelines first! This can be found in the
CONTRIBUTING.md file in the project. If it doesn’t exist, then file an issue and ask the maintainer to either make one or give you an idea of what they expect out of contributions.
- clone repo
If all that works then you’re ready to go. The last thing you want to do is clone a repo with failing tests, make your change, and think that your change is the reason the tests are failing! This has happened to me 🙁
Next, I try to follow the code in my head starting at the entry point where I’m interested in (like a function call, or a CLI with a certain argument). This can be intimidating for bigger projects, but it’s not as bad as you might think.
In my blogpost “What open source project should I contribute to?” I talk a little bit about how to find where the code is for a specific API.
Reading and running the tests is also useful. Breaking things can also be a helpful way to learn a codebase.
It’s a tried and true debugging mechanism:
console.log is a great way to learn a codebase. 👍 Even better if you can run it in the browser DevTools that’s also great. Read more about NodeJS debugging in Chrome DevTools.
One other thing you might try is running the project’s code in the context of your application. I talk about this a fair amount in my blog post from a few weeks ago “Spelunking in node_modules 👷”.
Something else that I’ve found helpful is to ask someone on the project to walk me through some part of the code. I try to make it worth their time by offering to record our conversation and make it publicly available.