Constructive Feedback
Let’s look at how to give constructive feedback in code reviews. We’ll show you a simple example and explain why the feedback matters.
The Scenario
A developer has written a function to calculate the total price of items in a shopping cart. The code may work but could be improved.
// Before
function calculateTotal(items) {
let total = 0
for (let i = 0; i < items.length; i++) {
total += items.price
}
return total
}How will you comment on this code?
Choose the option that you think is the most constructive and helpful.

Nice work! There’s a bug in the for loop where total is being incremented by items.price instead of items[i].price. This means that the loop is attempting to access a property directly on the items array rather than on each individual item object. Also, consider using reduce method to makes the code more concise and easier to read.

I’ve noticed an issue in your code, and there’s a more efficient way to do it.
Understanding the Improvements
Click here to learn more
1. Code Clarity
- The
reducemethod clearly shows we’re combining all items into a single value - The code is more declarative, showing what we want to do rather than how to do it
- Less code means fewer places for bugs to hide
2. Edge Case Handling
reducewith an initial value of 0 handles empty arrays correctly- The original code would also work with empty arrays, but it’s not as obvious
- The new version makes the behavior more explicit
3. Bug Prevention
- The original code had a potential bug:
items.priceinstead ofitems[i].price - The new version makes it impossible to make this mistake
- The structure of
reduceforces us to handle each item correctly
Tips for Giving Constructive Feedback
-
Start with Something Positive
- Acknowledge what works well
- Show you understand the code’s purpose
- Example: “Great work on the total calculation!”
-
Explain Your Suggestions
- Why is your suggestion better?
- What problems does it solve?
- Example: “The
reducemethod makes the code more concise and easier to read.”
-
Be Specific
- Point to exact lines or patterns
- Provide clear examples
- Example: “This handles edge cases better, like an empty array.”
-
Keep It Friendly
- Use encouraging language
- Focus on improvement, not criticism
- Example: “Thanks for making it more readable!”
Common Pitfalls to Avoid
-
Being Too Critical
- ❌ “This code is wrong. You should use
reduce.” - ✅ “Great work! Here’s a suggestion to make it even better.”
- ❌ “This code is wrong. You should use
-
Not Explaining Why
- ❌ “Use reduce instead.”
- ✅ “Using
reducemakes the code more concise and handles edge cases better.”
-
Ignoring the Positive
- ❌ “This needs improvement.”
- ✅ “Good work! Here’s how we can make it even better.”
Remember: The goal is to help your teammate write better code while maintaining a positive and collaborative environment!