Skip to content

Latest commit

 

History

History
244 lines (180 loc) · 9.64 KB

code-reviews.md

File metadata and controls

244 lines (180 loc) · 9.64 KB

Code Review Standards

This document outlines Bayat's standards and best practices for conducting code reviews. Code reviews are a critical part of our development process to ensure code quality, knowledge sharing, and continuous improvement.

Table of Contents

Core Principles

Our code review process is guided by these core principles:

  1. Quality Assurance: Identify bugs, vulnerabilities, and edge cases early.
  2. Knowledge Sharing: Spread knowledge and best practices across the team.
  3. Consistency: Ensure adherence to coding standards and architectural patterns.
  4. Mentorship: Provide opportunities for more experienced developers to mentor others.
  5. Continuous Improvement: Refine code and processes through constructive feedback.

Code Review Process

Before Submitting Code for Review

  1. Self-Review: Review your own code first:

    • Run automated checks (linters, tests, etc.)
    • Check for adherence to coding standards
    • Ensure adequate test coverage
    • Verify the code works as expected
  2. PR Preparation:

    • Create a focused, appropriately sized PR
    • Write a clear PR description explaining what, why, and how
    • Reference related issues or tickets
    • Include testing instructions
    • Add screenshots for UI changes
    • Highlight any areas of concern for reviewers

During Review

  1. Reviewer Selection:

    • At least one reviewer should be a domain expert
    • Include a mix of senior and junior developers when possible
    • Consider including someone unfamiliar with the code for fresh perspective
  2. Review Time Expectations:

    • Reviews should be completed within 24 business hours
    • For urgent PRs, notify reviewers via appropriate channels
    • Block time in your schedule for code reviews
  3. Review Process:

    • Reviewers should first understand the purpose and approach
    • Use the review checklist (see below)
    • Distinguish between required changes and suggestions
    • Provide constructive, actionable feedback
  4. Author Response:

    • Respond to all comments
    • Address required changes
    • Consider suggestions and provide rationale if not implementing
    • Request re-review once changes are made

After Review

  1. Merge Process:

    • PR can be merged once all required changes are addressed
    • Final approval by at least one reviewer is required
    • For complex changes, re-validation may be necessary
  2. Follow-up:

    • Track review comments for recurring issues
    • Consider improvements to standards or templates
    • Share learnings with the broader team if applicable

Review Checklist

General

  • Purpose: Does the code accomplish its intended purpose?
  • Complexity: Is the code as simple as possible for the required functionality?
  • DRY (Don't Repeat Yourself): Is there any duplicate code that should be refactored?
  • Error Handling: Are errors handled appropriately?
  • Edge Cases: Are potential edge cases considered and handled?
  • Security: Are there any security concerns (injection vulnerabilities, exposed credentials, etc.)?
  • Performance: Are there any obvious performance issues?
  • Accessibility: Does the code meet accessibility requirements (for UI components)?
  • Internationalization: Is the code prepared for internationalization if required?

Code Quality

  • Naming: Are variables, methods, and classes named clearly and consistently?
  • Comments: Are complex sections adequately commented? Are outdated comments removed?
  • Code Style: Does the code follow our style guidelines?
  • Readability: Is the code easily understandable to other developers?
  • Documentation: Is appropriate documentation included or updated?
  • API Design: Are public interfaces well-designed and documented?

Testing

  • Test Coverage: Are there sufficient tests for the changes?
  • Test Quality: Do tests validate the correct behavior rather than just the implementation?
  • Edge Cases: Do tests cover edge cases and error scenarios?
  • Performance Tests: For performance-critical code, are there benchmarks?

Architecture and Design

  • Architecture Alignment: Does the code align with the project's architecture?
  • Dependencies: Are dependencies appropriate and minimized?
  • Extensibility: Is the code designed to be extended if requirements change?
  • Patterns: Are appropriate design patterns used consistently?

Project-Specific Checks

  • Game Development: Are Unity/Unreal-specific best practices followed?
  • Web Development: Are frontend/backend separation concerns addressed?
  • Mobile Development: Are mobile-specific considerations (battery, memory, etc.) addressed?
  • Library Development: Is the public API well-designed and documented?

Code Review Etiquette

For Authors

  1. Be Open to Feedback: Approach reviews as an opportunity to learn, not as criticism.
  2. Explain Context: Provide background and context to help reviewers understand your choices.
  3. Respond to All Comments: Address each comment, even if just to acknowledge it.
  4. Don't Take Feedback Personally: The review is about the code, not about you.
  5. Break Down Large Changes: Keep PRs focused and manageable (under 400 lines when possible).

For Reviewers

  1. Be Respectful and Constructive: Focus on the code, not the person.
  2. Explain Reasoning: Explain why something should be changed, not just that it should.
  3. Prioritize Feedback: Distinguish between critical issues and nice-to-haves.
  4. Ask, Don't Tell: Phrase feedback as questions when appropriate ("Have you considered...?").
  5. Acknowledge Good Work: Point out exemplary code, not just issues.
  6. Be Specific: Provide concrete suggestions rather than vague criticism.
  7. Review Thoroughly: Superficial reviews provide little value; take the time to understand the code.

Example Feedback Phrasing

Instead of Consider
"This is wrong." "This might cause an issue when X happens. Consider handling it this way..."
"Why did you do it this way?" "I'm curious about the approach here. What was the reasoning behind this implementation?"
"Use X pattern here." "This seems like a good candidate for the X pattern because it would provide these benefits..."
"This code is messy." "This section could be more readable if we extracted this logic into a separate method."

Project-Specific Considerations

Game Development

  • Review scene and prefab changes carefully
  • Consider performance impacts, especially for runtime code
  • Check for frame-dependent logic issues
  • Validate component dependencies and nullability handling

Web Development

  • Review browser compatibility considerations
  • Check API contracts and error handling
  • Validate security practices (CSRF protection, XSS prevention, etc.)
  • Consider UX and accessibility guidelines

Mobile Development

  • Check for platform-specific handling
  • Review performance and battery usage implications
  • Validate responsive layouts and device compatibility
  • Consider offline functionality where appropriate

Library Development

  • Review public API design carefully
  • Check for backward compatibility
  • Validate documentation completeness
  • Consider extensibility and customization points

Automation and Tools

Automated Checks

Configure automated checks to run before manual review:

  • Linting: StyleCop, ESLint, etc.
  • Static Analysis: SonarQube, ReSharper, etc.
  • Test Coverage: Ensure minimum coverage requirements are met
  • Build Verification: Confirm the code builds successfully
  • Performance Benchmarks: For performance-critical changes

Code Review Tools

Effective use of code review tools:

  • Pull Request Templates: Use our standard templates for consistency
  • Inline Comments: Reference specific lines of code
  • Review Status: Use appropriate review states (approve, request changes, comment)
  • Suggested Changes: Use suggestion feature for simple fixes
  • Review Filters: Focus on specific files or changes when dealing with large PRs

Metrics and Continuous Improvement

Review Metrics

We track these metrics to improve our review process:

  • Time to first review
  • Time to merge after submission
  • Number of review iterations
  • Types of issues found in review
  • Test coverage changes

Process Improvement

The code review process itself should be regularly reviewed:

  1. Retrospectives: Discuss code review experiences in team retrospectives
  2. Standards Evolution: Update standards based on recurring feedback
  3. Training: Provide guidance for new team members on effective reviews
  4. Knowledge Sharing: Share code review learnings across teams

Additional Resources

Version History

Version Date Description
1.0 2025-03-20 Initial version