Code Reviews =================================== ✍️ **1. What is code review?** Read the code ... - Learn by looking at your own codebase - Search for patterns and anti-patterns - Quantify the quality of your code - Not exhausetive ... spot check The job of code review is to determine what is being done well as well as what can be done better. It is not a witch hunt. Sharing the findings of a code review makes all developers involved better. ✍️ **2. Why review code?** - Improve the quality of the team. - Impvove the quality of the communication. - Impvove the quality of the code. - Find codding problems. ✍️ **3. How to review code?** Taking your experience to bear... - Find things to laud and things to fix. - Look for repitive common problems, not one-off issues. - Don't review a lot of code. The rule of thumb is 200 - 400 lines at a time. - Reviewing the whole code-base is time consuming and probably not beneficial. - Remember that no code is perfect. Maintainable code is a feature! ✍️ **4. How not to review code?** There are patterns to reviewing code and there are anti-patterns too. - Don't get emotional. Remember the goal of a code review is to improve as an organization. So worrying about your code being reviewed or trying to put your stamp onto everyone else's code, both of them are going to be bad. So avoid emotionality when you're doing your code review. - Don't focus on blame. Don't find who wrote the code and try to find out what they're doing wrong or right. - Don't use the code review as an opputunity to figure out how to redesign the solution. That's not the job of the code review. - Don't judge based on how you would have coded it. This is a very common problem. So focusing on whether the code is good not on whether it's the way you would have done it. - Don't include one-off problems. Trying to find patterns to fix, not single bugs. ✍️ **5. How to Effectively Conduct a Code Review** Effective code reviews ensure software projects' quality, maintainability, and efficiency. Below are guidelines to help conduct effective code reviews: **Be clear on the objectives** Understand the purpose of the code review. It could be identifying bugs, improving code quality, ensuring adherence to coding standards, or providing feedback on design choices. **Review Small Chunks** Break down the code into manageable pieces and review them incrementally. It's easier to spot and address issues in smaller portions of code than to review large chunks at once. **Follow a Checklist** Create a checklist of common issues and best practices to review in each code review. This ensures consistency and helps cover all essential aspects. A checklist might include: - Code readability - Error handling - Performance optimizations - Security concerns - Adherence to coding standards **Provide Constructive Feedback** When identifying issues or areas for improvement, give clear and specific feedback. Focus on the problem itself rather than criticizing the developer. **Prioritize Issues** Not all issues are equally important. Prioritize critical issues that impact functionality, security, or performance. **Encourage Discussion and Collaboration** Code reviews should foster discussion and collaboration between team members. Encourage the developer to ask questions, clarify doubts, and provide their perspective. Promote knowledge sharing to improve the codebase. **Automate Where Possible** Use automated tools and static code analyzers to catch common mistakes and enforce coding standards. These tools save time and offer additional insights during the review process. **Learn from Each Review** Code reviews aren't just about improving the code; they also provide learning opportunities. As a reviewer, be open to feedback and different approaches from team members. Use the review process to enhance your coding skills. **Be Respectful and Positive** Code reviews are a collaborative effort to improve the codebase and achieve the best outcome. Be respectful and maintain a positive tone throughout the review. Celebrate good coding practices and offer constructive feedback on areas needing attention.