Other people’s code..


I touched on this briefly on my last update but by far the biggest challenge during my capstone project has been working with the existing codebase. My group is working on an industry backed project that adds extra functionality to an existing product. And making sense of the code has been tough.

I just finished a group meeting in which I helped a frustrated teammate out by showing them a single file among hundreds that contained the function they were struggling to figure out. Reading other people’s code can be so hard but I think it’s important to get somewhat comfortable with it before you start adding functionality.

Step 1: Run it

This is the most obvious step by far. Run the code, look at the console outputs, what are the inputs, what does the code actually do.

Step 2: read it

Look for the main or index function. Get familiar with the file structure. If you are looking at adding extra functionality, try to figure out where you would put it. You may find that a similar function already exists that you just need to repurpose. Research the libraries or frameworks you’re not familiar with. Open 75 stack overflow tabs while doing this research.

Step 3: Map it

By far the most helpful thing was my table of files/functions. I had 2 columns, the left column was for the file path and the right column listed each function in bold and what it did right below it. If I found it was calling a function in another file, I would add that file to the table. If I found a file that may be helpful but I haven’t seen used yet, I would add that file to the table. It’s definitely not necessary to do this for the whole codebase but it is so easy to lose files/functions when you are working with code you are not 100% comfortable with so this quick reference guide is invaluable.

Step 4: Log it

As you follow the calls, add print functions as needed. Look at what is being returned. If possible, run debug mode.

Step 5: Break it

If after all of this, you’re still not 80% comfortable with the existing codebase or are still overwhelmed. That’s ok! Sometimes the best way to learn is by doing. Don’t be afraid to break it. Just switch on over to your own git branch and take notes along the way!

Last thoughts

A lot of this stuff can seem very intuitive but it’s super easy to get overwhelmed when you’re starting at a large codebase. If you have a mentor, don’t be afraid to ask for help either. I also found writing down as much as I can of my mentor’s explanation can help a lot. You may not understand it in the moment, but you can make sense of it later.

Just remember to close all your stack overflow tabs once you’re done.

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *