Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How I Learn an Open Source Codebase

DZone's Guide to

How I Learn an Open Source Codebase

If you've ever been confused by another's OS codebase, this developer has some initial steps to help you untangle the code.

· Open Source Zone ·
Free Resource

Sensu is an open source monitoring event pipeline. Try it today.

What I do to learn and understand an open source project to which I want to contribute.

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 others' 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.

Some Steps

Here's a sequence of events I go through when I'm trying to learn or contribute to an open source project:

Contributing Guidelines

Look at the contributing guidelines first! This can be found in the README.mdor a 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.

Project Setup

When you set up the project on your computer, make sure that you first install the dependencies and that the tests pass (if there are any). For JavaScript projects, you can mostly do:

  • clone repo
  •  npm install 
  •  npm test 

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.

Follow the Code

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 blog post "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.

Break Tthings

Reading and running the tests is also useful. Breaking things can also be a helpful way to learn a codebase.

Log and Step Through

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".

Conclusion

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. This is appealing to maintainers because having material out there for new contributors to watch is very helpful. Here are some examples:

I hope this is helpful! Good luck!

From bare metal to Kubernetes, Sensu gives you complete visibility across every system and protocol. Get started today.

Topics:
open source ,open source codebase ,code confusion ,readme

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}