Code Reviews & LGTM: Best Practices & What You Need To Know
Are code reviews merely a necessary evil, or can they be a powerful catalyst for growth and improvement within a development team? Far too often, code reviews are treated as a formality, a checkbox to tick off before merging code, rather than a crucial opportunity for learning, collaboration, and enhanced code quality.
The world of software development is a dynamic landscape, constantly evolving with new technologies, methodologies, and best practices. At the heart of this evolution lies the code review, a process that, when executed effectively, can elevate a project from the mundane to the exceptional. But how often do we approach this critical step with the diligence and attention it deserves? Sadly, in many development environments, the code review process suffers from a widespread ailment: the "LGTM" (Looks Good To Me) mindset. This shorthand approval, while seemingly efficient, can mask a multitude of missed opportunities and potential pitfalls.
Aspect | Details |
---|---|
Definition | A systematic examination of source code by peers to identify and address potential issues, improve code quality, and share knowledge. |
Purpose | Enhance code quality, catch bugs early, share knowledge, ensure adherence to coding standards, promote collaboration, and build team trust. |
Key Components | Code correctness, code comprehension, adherence to coding standards, security considerations, performance optimization, and potential for future maintainability. |
Common Pitfalls | Superficial reviews, the "LGTM" mentality, lack of clear guidelines, inadequate time allocation, focusing solely on mistakes, and a negative review atmosphere. |
Benefits of Effective Reviews | Reduced bug rates, improved code maintainability, faster onboarding of new team members, enhanced team communication, and a culture of continuous learning. |
Tools and Techniques | Tools like Git, GitHub, and Phabricator facilitate code reviews. Techniques include pair programming, static analysis, and automated code scanning. |
Best Practices | Establish clear guidelines, allocate sufficient time, focus on both strengths and weaknesses, provide constructive feedback, and foster a positive review environment. |
Impact on Team Dynamics | Effective code reviews foster trust, build community, and promote a shared understanding of the codebase, leading to a more collaborative and productive team. |
Reference Website | Atlassian - Code Review Best Practices |
The very essence of "LGTM" a concise affirmation of approval can paradoxically undermine the very process it is intended to expedite. Consider the implications: a developer submits their code, a peer grants the coveted "LGTM," and the code is merged. But what if a critical bug, a subtle inefficiency, or a violation of coding standards slips through the cracks? The "LGTM" has essentially become a blind spot, a signal that the code appears to function as intended, without a deeper examination of its quality and long-term implications.
This is not to say that the "LGTM" is inherently malicious or that it should be completely abandoned. It has its place. When a developer has thoroughly reviewed the code, understands its functionality, and finds no significant issues, the "LGTM" can be a quick and efficient way to signal approval. However, it should never be a substitute for a thorough, thoughtful review. The goal should always be to ensure the code is not just "good enough," but the best it can be, given the project's goals and constraints.
Code reviews are more than just a chore standing in the way of deployments; they are an investment in the future of the codebase and the skills of the development team. When approached correctly, code reviews foster a culture of continuous learning, where developers learn from each other, share their knowledge, and collectively improve the overall quality of the software. This is especially crucial in larger teams or projects with complex codebases. Thorough reviews are essential for finding and addressing potential errors, security vulnerabilities, and design flaws.
Let's consider a common scenario, a microcosm of the challenges many developers face. Imagine a developer, let's call her Sally, new to a company and eager to make a positive contribution. She diligently writes her code, submits it for review, and receives the coveted "LGTM" from a senior peer. Emboldened by the apparent approval, she proceeds to merge the code into the main branch. Unbeknownst to her, a subtle bug, a single line of code with a hidden flaw, has slipped through the review process. It might have been caught with a more careful examination, or through the use of automated tools, but instead, it went unnoticed. The consequences? Potentially, a production outage, frustrated users, and a loss of time and resources to fix the issue.
The responsibility for code quality rests on the shoulders of every developer, not just the author of the code. While the author is responsible for the initial creation, reviewers are the gatekeepers, ensuring that the code meets the highest standards of quality, security, and maintainability. Experts should review code, particularly in areas where they possess specialized knowledge. Thorough code reviews can help avoid these situations and promote a better work environment. Code reviews should also focus on highlighting good practices and offering encouragement, which fosters a positive and collaborative environment.
One way to approach code reviews is to focus on the following key areas. First, make sure the code works as expected. Does it fulfill the requirements? Second, check for potential bugs, vulnerabilities, and performance issues. Third, review the code's readability and maintainability. Is it easy to understand and modify in the future? Fourth, assess the code's adherence to coding standards and style guides. Is it consistent with the rest of the codebase?
Beyond the technical aspects, code reviews can serve as invaluable opportunities for mentorship and professional development. By taking the time to explain design choices, point out areas for improvement, and share best practices, experienced developers can help their less experienced colleagues grow and hone their skills. It can be more valuable to share what someone did right rather than what they did wrong.
The concept of "LGTM" in the context of code reviews, while seemingly harmless on the surface, is often symptomatic of a deeper issue. It can indicate a lack of time dedicated to thorough reviews, a reliance on superficial checks, or even a reluctance to challenge the work of colleagues. This can lead to several negative outcomes, including a decline in code quality, increased technical debt, and a diminished sense of shared responsibility for the codebase. It is time to change the dynamic.
Code reviews should be viewed not as a roadblock, but as a valuable asset. When performed diligently and thoughtfully, they can become the cornerstone of a thriving development culture. They can foster a shared understanding of the codebase, encourage collaboration, and facilitate the transfer of knowledge among team members. They are more than a task to be completed; they are a process to be embraced.
In fact, when done well, code reviews can be used to build community, trust, and teach. Newer developers can learn by reviewing code, deferring to others for approval decisions. For experienced developers, it's a chance to pass on knowledge and mentor others. The use of "LGTM" has become so widespread that it's now a standard part of the process.
Fortunately, there are tools and resources available to help developers conduct more effective code reviews. Platforms like GitHub, GitLab, and Bitbucket offer robust code review features, enabling developers to comment on code, suggest changes, and track the progress of the review process. There are also a variety of static analysis tools that can automatically detect common code quality issues, such as style violations, potential bugs, and security vulnerabilities. These tools can help streamline the review process and ensure that code adheres to established standards.
Beyond the technical tools, there are also several best practices that can help improve the effectiveness of code reviews. First, it's essential to establish clear guidelines for code reviews. This should include clear expectations for code quality, coding style, and testing. Second, it's important to allocate sufficient time for code reviews. A rushed review is unlikely to catch all the potential issues. Third, reviewers should focus on both the strengths and weaknesses of the code. Providing constructive feedback, along with positive reinforcement, can create a more supportive and collaborative review environment. Fourth, the code author should be responsive to feedback and be willing to make necessary changes to improve the code.
In 2020, GitHub Code Scanning was launched in public beta and became generally available later in the year. It's powered by an analysis engine that scans code for vulnerabilities and code quality issues. Today, GitHub Code Scanning has many of the same key features as other tools and more. Be sure to familiarize yourself with the code review process from the official contribution guide first. There are several terms code reviews may use that you should become familiar with such as "LGTM", "SGTM", "PTAL" and "S/foo/bar/".
Code review information from critiques can also be helpful when doing code archaeology and when following some technical decisions explained in code review interactions. Though critique isn't the only code review tool used at Google, it is the most popular one by a large margin. Together, the code correctness and code comprehension checks are the main criteria for an LGTM from another engineer, which is one of the approval bits needed for an approved code review. When an engineer marks a code review as LGTM, they are saying that the code does what it says and that it is understandable.
Consider the impact on team dynamics. Effective code reviews foster trust and promote a shared understanding of the codebase. They build community and allow developers to learn from each other. This creates a more collaborative and productive team, one that is more resilient to change and more capable of delivering high-quality software. They reduce code ownership and enable learning amongst team members. Moreover, code reviews aren't just focused on mistakes; they encourage good practices, too. It's as important to tell a developer what they did right as it is to tell them what they did wrong. The goal should be to provide more value with each review, fostering a culture of learning and improvement.
In conclusion, the path toward more effective code reviews requires a fundamental shift in mindset. It requires a move away from the "LGTM" mentality and a recognition that code reviews are far more than just a formality. They are an opportunity to improve code quality, build team trust, and foster a culture of continuous learning. By embracing this perspective and investing in the tools, techniques, and best practices outlined above, development teams can transform their code review process into a powerful engine for growth and innovation.


