Skip to Content

Code Readability

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

The Scenario

A developer has written code to check if a user is eligible to drive. The code works but could be more readable.

drivingEligibility.ts
// Before function canDrive(user) { return ( user.age >= 16 && user.hasLicense && !user.isSuspended && user.visionTestPassed && user.medicalCheckPassed ) }

PR Comment

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

// After function canDrive(user) { const meetsAgeRequirement = user.age >= 16; const hasValidLicense = user.hasLicense && !user.isSuspended; const passedRequiredTests = user.visionTestPassed && user.medicalCheckPassed; return meetsAgeRequirement && hasValidLicense && passedRequiredTests; }

Click here to learn more

Improvements

1. Code Clarity

  • Original code has a long, complex condition
  • New code uses descriptive variable names
  • Clear explanation of each requirement

2. Maintainability

  • Easier to understand and modify
  • Easier to debug issues
  • Easier for new team members to learn

3. Documentation

  • Code is self-documenting
  • No need for additional comments
  • Clear for other developers

Tips

1. Start Positive

  • Acknowledge the working code
  • Show you understand the current approach
  • Example: “Great work on the driving eligibility check!“

2. Explain the Benefits

  • Why does readability matter?
  • How does it help the team?
  • Example: “This makes the code’s intent clearer”

3. Be Specific

  • Suggest concrete improvements
  • Explain why they matter
  • Example: “Using descriptive variables helps other developers understand the logic”

4. Keep It Friendly

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

Common Pitfalls to Avoid

1. Being Too Critical

  • ❌ “This code is unreadable. Fix it.”
  • ✅ “Good work! Here’s how we can make the code even clearer.”

2. Not Explaining Why

  • ❌ “Break this into smaller parts.”
  • ✅ “Breaking down the condition into descriptive variables helps other developers understand the business logic.”

3. Ignoring the Positive

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

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

Last updated on
Code EfficiencyCoding Standards