ApiaryActive
Try: pause · settings · learn · wipe
← Community / Reading Room
CR
quality · 2 min read

code review principles

Code reviews are an essential part of maintaining high-quality code in the APIary platform. As founders, it's crucial to strike a balance between providing…

Code reviews are an essential part of maintaining high-quality code in the APIary platform. As founders, it's crucial to strike a balance between providing constructive feedback and being approachable and respectful to developers. In this article, we'll outline the key principles of code review, including what to look for, when to nitpick vs let go, and how to give feedback without bruising egos.

What to Look For

When reviewing code, consider the following aspects:

Readability

  • Is the code well-structured and easy to follow?
  • Are variable names descriptive and consistent throughout the codebase?
// Good practice: Descriptive variable name
const userCredentials = {
  username: 'johnDoe',
  password: 'secretPassword'
};

// Bad practice: Ambiguous variable name
const data = {
  username: 'johnDoe',
  password: 'secretPassword'
};

Maintainability

  • Is the code modular and easy to understand?
  • Are there any duplicated code blocks or repeated logic?
// Good practice: Modular code with separate functions
function validateUserInput(input) {
  const isValid = input.username && input.password;
  return isValid;
}

function processUserRequest(data) {
  if (validateUserInput(data)) {
    // Process user request
  } else {
    // Handle invalid input
  }
}

Performance

  • Are there any performance bottlenecks or potential issues?
  • Is the code optimized for the given use case?
// Bad practice: Inefficient database query
const users = db.query('SELECT * FROM users WHERE username = ?', [username]);

// Good practice: Optimized database query with indexing
const users = db.query('SELECT * FROM users WHERE id IN (?)', [userIds]);

When to Nitpick vs Let Go

It's essential to strike a balance between providing feedback and being respectful of developers' time and effort. Here are some guidelines:

  • Nitpick when necessary: If the code is causing issues or has significant performance implications, address these concerns directly.
  • Let go when minor: Focus on high-priority issues and leave minor suggestions for future iterations.

How to Give Feedback Without Bruising Egos

When providing feedback, keep the following tips in mind:

  1. Be specific: Instead of saying "this is bad code," specify what exactly needs improvement.
  2. Focus on behavior, not person: Avoid making personal attacks or comments that can be perceived as negative.
  3. Offer solutions: Provide actionable suggestions for improvement.
// Bad feedback: Personal attack
"This function is a mess! Can you rewrite it?"

// Good feedback: Specific suggestion
"Consider using a more efficient algorithm to improve performance."

Related/Sources

By following these code review principles, you'll be able to maintain high-quality code while fostering a positive and collaborative environment for developers.

Frequently asked
What is code review principles about?
Code reviews are an essential part of maintaining high-quality code in the APIary platform. As founders, it's crucial to strike a balance between providing…
What should you know about what to Look For?
When reviewing code, consider the following aspects:
What should you know about when to Nitpick vs Let Go?
It's essential to strike a balance between providing feedback and being respectful of developers' time and effort. Here are some guidelines:
What should you know about how to Give Feedback Without Bruising Egos?
When providing feedback, keep the following tips in mind:
What should you know about related/Sources?
By following these code review principles, you'll be able to maintain high-quality code while fostering a positive and collaborative environment for developers.
References & sources
  1. Apiary Reading RoomOpen, cited knowledge base — funded to keep bee & practical research free.
From the Apiary Reading Room. Opinion & editorial — not financial advice. We don't overclaim.
More from the Reading Room