3 Steps to Reading New Code

Man writing some code

Approaching Code For The First Time

Whether you are approaching a code base for the first time or you are doing a code review for another developer, reading code may be like reading another “language”. In school, you get extensive instruction on how to write code, but rarely hear about how to approach a large code base for the first time. And then you enter the “real world” and learn that reading code is as essential a skill as writing.

A lot of our new engineers see codebases that are significantly larger than what they were presented with during their undergraduate work. This can certainly be overwhelming. Organizing it all in your head is often impossible in active codebases. We share three tips with our new engineers to make new code less intimidating.

Step 1: Look for the Documentation

When you are looking at a new codebase, the first place to look is a README file. This text file is typically located in the root folder of the codebase. There are a few things that this document should include to make the process easier for the reviewer:

  • What tools you need installed to compile this code
  • How you can run the code or the context it is used in
  • What the code is doing
  • What different blocks are doing

Step 2: Look for Entry Points

Next, you will want to identify your entry points and programs that will be most beneficial to your review. We suggest you open up your code, in an IDE or another editor that understands the declarations, can do syntax highlighting, and can do code folding, so you can squeeze the code down into just the headers and stay high level. If you’re in C, the entry point is usually going to be your main() function in a main.c file. If you’re using the Arduino framework, the setup() and loop() functions in the INO file are the entry points. Python will have the package name and the entry point will often be in a file with the same name. You will find either a main function or code will start executing from the top of the file. If you’re in C sharp, you’ll find a Main() or OnStartup() function in either an Application.cs or Program.cs file.

If you’re in C++ or C, start in your header files, just see what things are being called and avoid getting mired down in details of how exactly each function is implemented.

Step 3: Take a 10,000 foot view

Once you have found the entry point, identified the main function and/or the top files, now you can see where the code is going. Taking notes in the form of a sketch or diagram block helps this process, and can also help to identify how things relate to each other visually.

When you are looking at code for the first time because you’re going to start developing with others, taking a look through the recent history and active branches in the repo can help you understand the code as well. This will give you insight on where active work is happening, what others are watching for, what is changing. Looking through this history may even provide you hints on what parts of the code are most important.

What To Ignore As Long As You Can

While reviewing code, there may be a temptation to fix all the things you see. Perhaps because they are not the way you would do them or you could recommend a better way. This is where we encourage you to pause. Here are a few things you can ignore.

In short, anything that can be caught or fixed by automated processes are better reviewed by those processes. If you don’t have these in place, we have some articles discussing the how and why of automation, too!

Reading code is as important as knowing how to write it. While this is not a skill that is taught, it can absolutely be valuable to your team and clients. And if you have questions about an embedded project you’re working on, consider reaching out! At DojoFive, we have talented engineers on hand ready to help you with all aspects of your EmbedOps journey. We are always happy to help with interesting problems that need solving. You can reach out at any time on LinkedIn or through email!

Discover why Dojo Five EmbedOps is the embedded enterprise choice for build tool and test management.

Sign up to receive a free account to the EmbedOps platform and start building with confidence..

  • Connect a repo
  • Use Dev Containers with your Continuous Integration (CI) provider
  • Analyze memory usage
  • Integrate and visualize static analysis results
  • Perform Hardware-in-the-Loop (HIL) tests
  • Install the Command Line Interface for a developer-friendly experience

Subscribe to our Monthly Newsletter

Subscribe to our monthly newsletter for development insights delivered straight to your inbox.

Interested in learning more?

Best-in-class embedded firmware content, resources and best practices

Laptop with some code on screen

I want to write my first embedded program. Where do I start?

The boom in the Internet of Things (IoT) commercial devices and hobbyist platforms like the Raspberry Pi and Arduino have created a lot of options, offering inexpensive platforms with easy to use development tools for creating embedded projects. You have a lot of options to choose from. An embedded development platform is typically a microcontroller chip mounted on a circuit board designed to show off its features. There are typically two types out there: there are inexpensive versions, sometimes called

Read More »
Medical device monitoring vitals

IEC-62304 Medical Device Software – Software Life Cycle Processes Primer – Part 1

IEC-62304 Software Lifecycle requires a lot of self-reflection to scrutinize and document your development processes. There is an endless pursuit of perfection when it comes to heavily regulated industries. How can you guarantee something will have zero defects? That’s a pretty hefty task. The regulatory approach for the medical device industry is process control. The concept essentially states that if you document how every step must be completed, and provide checks to show every step has been completed properly, you

Read More »
Operating room filled with medical devices

IEC-62304 Medical Device Software – Software Life Cycle Processes Primer – Part II

Part I provides some background to IEC-62304. Part II provides a slightly more in-depth look at some of the specifics. The IEC 62304 Medical Device Software – Software Lifecycle Processes looks into your development processes for creating and maintaining your software. The standard is available for purchase here. So what activities does the standard look at? Here are some of the major topics. For any given topic, there will be a lot more specifics. This will look at a few

Read More »