Cracking the Code: Mastering the Art of Reading Code for New Developers
Find the easy, medium and hard way of reviewing code so that you can go from successful solo developer to successful team developer
Hey Awesome Peeps,
How can you review pull/merge requests and provide valuable comments?
This is one of the first challenges that you face as a new developer in a new organization as you are not aware of most of the context.
This question then leads to another question -
How you can read code effectively so that you understand the pull request, enabling you to give meaningful comments?
Understanding existing codebases is crucial for learning from experienced developers, collaborating with teams, and troubleshooting issues.
So the next question.
How do you read code effectively? Here are the 3 approaches that you can take based on time constraints.
Short of time
You do not have so much time to review the code. You can skim through the code and check for things that jump out of you. Some of the examples would be:
Validate comments if any. Are the comments current and help reading the code?
Nested loops and conditional statements
Log statements - Are they providing useful information for debugging? Are they exposing personally identifiable information (PII) if that is something that you need to be concerned about in the industry you are in?
Check the naming to understand if they make sense
Complex or large methods
Incorrect or improper use of a library that you know at the top of your mind
Are there unit tests that cover different scenarios?
The code snippet just doesn’t feel right
An hour to review
You have got some more time now. So now you checkout the code on your IDE for review. Key things to check:
All the points in the “Short of Time” section
Look up the documentation for the libraries if you are unsure of their usage
Can a design pattern be used for this scenario? Or would an alternate design pattern make be a better approach?
Is there a piece of code that is already implemented elsewhere in the codebase so that you can reuse it?
Are there any unused methods or arguments? Most IDEs flag them but sometimes developers may miss it.
Does the code use any anti-pattern that you are aware of?
Have about half a day or the PR is critical
You have permission to go deeper. Key things to check:
All the points mentioned in both sections - Short of Time and An hour to review
Think from a requirement perspective if any scenario is missed
Can you refactor the code to make it better?
Can you abstract a piece of logic to make it better? Better still, would be able to provide an alternate suggestion.
Does this PR create any potential tech debts?
Can the code use better libraries to improve the code?
Appreciate it if something’s done in a better way
Benefits
Becoming a successful developer involves more than just writing code.
It also requires the ability to understand and analyze existing codebases effectively.
Reading code may not seem as glamorous as writing it, but it is an essential skill that can significantly impact your growth as a developer.
A few of the benefits of doing a deep review are:
Learning from Experts
One of the primary advantages of reading code is the opportunity to learn from experienced developers.
By studying well-written codebases, you gain insights into industry best practices, design patterns, and efficient coding techniques.
Reading code exposes you to different coding styles and approaches, broadening your knowledge and improving your problem-solving skills.
It allows you to understand how seasoned developers tackle complex problems and make informed decisions, enhancing your own coding abilities in the process.
Enhancing Collaboration
Reading code enables effective collaboration with other developers, allowing you to contribute meaningfully to team projects.
By understanding existing codebases, you can quickly integrate with ongoing projects, comprehend the logic behind existing features, and propose improvements or bug fixes.
Reading code also encourages code reviews, enabling team members to share knowledge, identify potential issues, and ensure code quality.
Debugging and Troubleshooting
By studying code written by others, you gain insights into different error scenarios, identify common pitfalls, and discover effective debugging techniques.
This helps you diagnose problems more efficiently and develop a systematic approach to troubleshooting.
Additionally, reading code allows you to understand the context of the codebase, making it easier to trace the flow of data and identify potential areas of concern.
Conclusion
Reading code empowers you to learn from experts, build a strong programming foundation, collaborate effectively with peers, troubleshoot efficiently, and fuel continuous growth.
By investing time in reading code, you unlock a world of knowledge, gain exposure to real-world scenarios, and develop a deeper understanding of coding principles.
PS: Have I missed anything? Chime away in the comments.
Weekend Reads
Trunk-based vs feature-based development: Understanding the difference.
Introduction to Domain-Driven Design: Domain-Driven Design and Microservices
8 Japanese Techniques to Overcome Laziness & Achieve Success: Not sure if Pomodoro is a Japanese technique. But this is a good list.