Skip to Content

Documentation

Let’s look at how to suggest improvements for code documentation in code reviews. We’ll show you a simple example and explain why the feedback matters.

The Scenario

A developer has written code to handle user data. The code works but could benefit from better documentation.

proccessUser.ts
function processUser(userId: string) { const user = db.getUser(userId) return user }

PR Comment

Choose the comment that you think is the most constructive and helpful.

/** * Retrieves and processes user data from the database. * * @param userId - The unique identifier of the user to process * @returns The processed user data * @throws { UserNotFoundError } If the user is not found in the database */ function processUser(userId: string) { const user = db.getUser(userId) return user }

Click here to learn more

Improvements

1. Code Clarity

  • Original code lacks documentation
  • New code has clear JSDoc comments
  • Better understanding of requirements

2. Maintainability

  • Clear function purpose and parameters
  • Documented error cases
  • Better for team collaboration

3. Future Maintenance

  • Easier to update requirements
  • Clear documentation of changes
  • Better for onboarding new developers

Tips

1. Start Positive

  • Acknowledge the working code
  • Show you understand the current approach
  • Example: “Great work on the user processing!“

2. Explain the Benefits

  • Why does documentation matter?
  • How does it help other developers?
  • Example: “This makes the code more maintainable”

3. Be Specific

  • Suggest concrete improvements
  • Explain why they matter
  • Example: “Adding JSDoc comments helps with code understanding”

4. Keep It Friendly

  • Focus on improvement, not criticism
  • Use encouraging language
  • Example: “Thanks for considering documentation!”

Common Pitfalls to Avoid

1. Being Too Critical

  • ❌ “This needs documentation.”
  • ✅ “Good work! Here’s how we can make it even more maintainable.”

2. Not Explaining Why

  • ❌ “Add comments.”
  • ✅ “Adding JSDoc comments helps other developers understand the code.”

3. Ignoring the Positive

  • ❌ “This needs better documentation.”
  • ✅ “Great work! Here’s how we can make it even more helpful.”

Remember: The goal is to help your teammate write better code while maintaining a positive and collaborative environment!

Last updated on
CompatibilityDomain Types