In this lesson, you will learn how to phrase your technical observations in a pull request to improve code quality while fostering a supportive team culture.
The Art of Constructive Code Review
When reviewing a teammate's code on GitHub, your goal is twofold: ensuring the codebase remains clean and helping your peers grow. A common pitfall is focusing too heavily on "you" statements (e.g., "You did this wrong"), which can sound accusatory. Instead, focus on the code itself and the shared objective of maintaining project standards.
Use the "Suggestion" Framework
Rather than just pointing out a flaw, frame your feedback as a question or an explanation of why a change might be beneficial. This invites the author into a conversation rather than presenting them with a command.
Instead of:
"Your loop here is inefficient. Change it to a map function."
Try this:
"I noticed this
forloop could potentially cause performance issues with larger datasets. Would using a.map()function be cleaner here? It might also make the logic easier to read for future maintainers."
Incorporate GitHub’s "Suggested Changes"
When you see a specific syntax error or a minor refactoring opportunity, use GitHub’s Suggested Changes feature. This allows you to propose a direct edit within your comment that the author can apply with a single click.
// Instead of just saying "Fix this syntax," you can use the suggestion block:
- const data = fetch(url);
+ const data = await fetch(url);
By providing the fix directly, you show that you are invested in solving the problem alongside your teammate, rather than just acting as a gatekeeper.
Focus on "Why," Not Just "What"
Always link your feedback back to the project’s goals—such as performance, security, or readability. When a teammate understands that you aren't just being pedantic, but are instead looking out for the long-term stability of the application, they are much more likely to welcome your input. Keep your tone curious, professional, and collaborative.
Key Takeaway: Effective code reviews focus on the code, explain the "why" behind suggested improvements, and utilize collaborative tools to help the author implement changes quickly.