Code comprehension: an underrated skill
Published: 2023-04-03 06:10:18

Code comprehension is the skill of reading and understanding code.  It is an important skill for any engineer but it is rarely mentioned alongside other skills an engineer needs.  In fact I would say it is just as important as being able to write code. 

Before you began your career it is likely that all of the code you worked on was written by you from scratch. This code will be easy for you to understand because you wrote it. Now that you are working as an engineer you are more likely to be adding code to an existing codebase rather than writing code from scratch. This means that you will be working with code that you are not familiar with. It is important that you understand the code that you are changing before you change it. If not, then it is likely that you will break the code you are trying to change in a confusing way. 

When I see a junior engineer with weak code comprehension skills they will get lost in the code. They will make a change that causes an error to occur or a test to fail. They will then have to debug the problem but because they didn't understand the change they made to the code, it is even harder for them to fix it.  In the worst case this happens for every change they make and then it seriously slows them down. They get stuck in a cycle of change,  break, debug, change, break, debug...

#How to improve your code comprehension

To improve at code comprehension there is no substitute for just reading code. The more you read and understand the better you will become.  That being said there are a few things you can do to help yourself along the way.  

###1. Ensure you understand the syntax of the code you are reading. 

If you don't understand the syntax then you will struggle to read the code. Each language has its own way of laying out and describing code.  Semicolons, braces, angled brackets, colons  keywords, arrows, brackets and indentation may all hold meaning depending on the language you are reading. Learn these. If you find bits of code that you don't understand when reading it then make a note of these gaps.  They are something you should learn and practice.

###2. Use the navigation tools built into your IDE

Your IDE will have features designed to help you navigate code.  They can help you move from a usage of a function to where the function is defined,  they can help you to search code and move through windows and tabs quickly. Learn these features and shortcuts to help you move through the code easily. VS Code has a guide [here](https://code.visualstudio.com/docs/editor/editingevolved) and JetBrains has a guide [here](https://www.jetbrains.com/help/idea/navigating-through-the-source-code.html).

###3. Understand the context

Before diving into the code,  try to understand the context of the application first.  What is the purpose of the app, tool or repo whose code you are reading? What are it's major features? Ask a colleague to answer these questions for you. It's much easier to decipher the code when you know what it is supposed to be doing.

Reading and understanding code is something that you will just get better at over time. I hope these tips will help you on that journey. It is important to persevere with this skill because it will help you become a better engineer.  If your code comprehension is strong you will be able to add new functionality and debug issues more quickly. It will help you learn to appreciate well-written code and be able to develop a sense of what is well-written and what is not. All of this will help you as you move towards being a mid-level engineer.

Happy reading!


{% embed https://dev.to/andrewkelly %}