4 ways to get started with a codebase

4 ways to get started with a codebase

At the beginning of my career, I always got stuck on seeing multiple files and modules since as beginners we just practise by programming everything in a single file and get started from there. The moment there are multiple files and imports things get confusing for the beginner. In this post, I transfer the sane advice that my mentor gave me for understanding the functionality of a codebase

The expected skills are using a debugger in the language used and a basic understanding of the features of any language (for loops will be for loops in any language and if conditions will be if conditions, the syntax might change but the basic idea is the same)

Photo by Pankaj Patel on Unsplash

Tests

Tests in a codebase are generally a good starting point since they outline what the functionality is and test with an example. The tests usually contain an example input and assert statements confirming the type of the output or the expected output itself. This helps understand the input-output relation for a particular function. Now that is cleared the next step is to read the function to understand what exactly the function does and how it does it.

For this, I prefer using the debugger with the test. It is possible to create breakpoints in the function and understand what transformations are happening to the data while passing through the function.

Now for a scenario that is very common, what if there are no tests in the codebase?

Examples

If there are no tests in the codebase the next thing to do is to check examples of usage of functions, for this you need your nearest mentor but then they can point you to where the module ends up getting used and follow the steps in the previous example with a debugger to get a detailed understanding of the code.

Documentation

Photo by Sigmund on Unsplash

Sometimes the documentation is the best place to start, there are many examples of great documented resources, most large python libraries are documented in a great way as also frameworks like docker and Kubernetes. This document contains basic examples of how to use their software. Something similar should exist for internal software and if they do exists is a good place to start.

Pair Program

Photo by Alvaro Reyes on Unsplash

This is a very fail-safe way since other points mentioned in the post may or may not be available. It is preferable to request some time from the code owner (The guy who maintains or is responsible for the functionality) to show the ropes around the codebase.

If the code base is too big then this can take a lot of time from that person so make sure to get the examples and starting points of usage so that it is easier to get started.

Conclusion

I hope this helps in understanding how to approach a new codebase as a beginner. The debugger (sometimes print statements) is a very useful skill to learn. If you have better ideas on how to go through a codebase please mention them in the comments section.