Reviewing code has been promoted as a great solution for improving code quality in any project. While this is true, the primary advantage lies in how code reviews alter your approach to solving code problems. Any code can be reviewed, but some best practices will make the reviews more valuable.
Why review code?
Let's focus first on why we want code to be reviewed. Understanding why code reviews are valuable should help us maximise the benefits of a review.
In its most simple form, reviewing code is about validation. Validating if my solution to a problem is not flawed and may introduce new problems. Having someone else review your code is a good way to identify and address edge cases that you might have overlooked. Each team member has different experiences with the application (and code in general) and might see an impact on other aspects of the application.
Additionally, code review is also an effective way to validate whether a solution is suitable for the application. A solution might work, but not fit the culture or already existing best practices. Sometimes, a quick fix may not align with the system’s long-term architecture or established practices, particularly in trends such as AI-assisted coding or rapid prototyping.
The Learning Opportunity
Code reviews are valuable learning experiences for everyone involved, not just for junior developers. They’re a way to share insights about the codebase, historical decisions, and the bigger business context.
What Can a Code Review Offer?
Reviews can:
- Reveal overlooked edge cases in code and business logic
- Catch missing or incomplete test paths
- Validate solutions against established best practices
- Maintain consistency in project design patterns (like using CommandBus)
- Spark discussions that lead to architectural improvements or needed refactoring
- Highlight clever solutions and inspire new approaches within the team
It is tempting to put uniform code-styles as one of the goals, but that is not something that should be validated in each code review. A team should have agreed on a ruleset beforehand and not spent any more energy on it.
Making Code Reviews valuable
It’s all fun and games until you need to review code that consists of 64 changed files with 3000 changed lines of code. After a long time of trying to figure out the code, you’ll most likely come to the conclusion that you still don’t know what this code is actually fixing.
To keep reviews effective and manageable, remember these tips:
- Review small changes: Limiting reviews to around 200-300 lines helps catch more issues.
- Focus on one problem at a time: Single-purpose changes are easier to review and understand.
- Provide context: Assume reviewers aren’t familiar with your task. Explain the what and why behind your changes, anticipate likely questions, and add links to discussions or relevant tickets when helpful.
- Use reviews as documentation: Think of code reviews as a living record, similar to git blame. At madewithlove, we suggest everyone add a changelog summary for each review, enough detail for simple cases, and expanded notes for bigger changes.
Code reviews with AI
Artificial intelligence is transforming the code review process. AI-powered tools can quickly identify recurring patterns, suggest more efficient code structures, and automate the detection of common errors and security vulnerabilities. These systems handle repetitive tasks, improving accuracy and saving valuable time for development teams. Despite these benefits, human oversight remains essential. Only experienced developers can fully understand project context and make nuanced decisions, ensuring code reviews are both technically sound and aligned with long-term goals.
Don’t forget AI code assistants Code
AI coding assistants (such as Cursor) can catch mistakes before they escalate and identify edge cases that developers might miss. By quickly analysing code, they can suggest improvements and point out areas that could confuse team members. Embracing AI doesn't just expedite the review process; it also fosters a more effective environment for teamwork and learning. Tools like DeepCode and CodeGuru can scan code to spot mistakes and suggest improvements.
However, there are valid concerns. Some worry AI could overlook complex issues or misunderstand the original intent behind the code. Additionally, over-reliance on AI might reduce developer engagement in the review process.
Balancing AI with human insight is crucial for an efficient and effective code review process. While AI integration is promising, its potential challenges must be considered. Code reviews are crucial for ensuring the quality of software, and AI can significantly enhance this process. If you need help getting started or implementing best practices, we're here to assist.
How code reviews change us
If you follow those guidelines, you’ll notice that you need to think about your solution in more minor and incremental changes. It will force you to complete tasks in smaller increments. You will need to isolate one change from your problem, fix it, and request a code review. If it’s approved, it can be deployed while you work on the following incremental change in your problem.
As a result, your code will be reviewed much more thoroughly, and you’ll be able to get feedback faster. As a bonus, you’ll be able to deploy faster.
Resources
- You don't need more engineers
- Why you should avoid over abstracting
- Getting started with performance testing
- PHP type hints: Self and parent
- How to pragmatically leverage AI as a startup
- Introduction to Domain Driven Design
- The end of AI-powered
- Cloudy with a chance of function calls
- Laravel’s Ecosystem
- Makefiles for automation and better dev UI
Member discussion