This page looks best with JavaScript enabled

How to Do Code Review Better

 ·  ☕ 2 min read

1. How to Do Code Review Better

RequirementItems
Requirements for the committerSmall granularity
Atomicity
With comments
Tool checks
Requirements for the reviewerFirst conventions
Second logic & performance
Third design
Requirements for the teamReviewing the old to learn the new

2. Define a Code Review Checklist

RequirementItems
NamingVariable names
Class naming
Method naming
Parameter naming
Code lengthClasses no longer than 1000 lines
Methods no longer than 100 lines
Conditional nestingAvoid nesting multiple if and loop statements
Avoid overly long conditions
Parameter and return value checksAt most 3 parameters recommended
Validate parameters (e.g. null checks, container length)
Validate return values (e.g. null checks, container length)
Reuse of well-encapsulated codeDoes the interface use shared code libraries, such as Kresource, Kcontent, KPackageManager, etc.
CommentsDo classes, key steps, and external interfaces have comments

3. Look at Logic & Performance

RequirementItems
Main-thread logic checksAvoid time-consuming operations such as file and network I/O on the main thread
Threshold checksAre access frequencies set, and is there a cap
Are file sizes and counts capped
Is network traffic capped
Multithreading issuesDoes it produce dirty data
Are synchronization locks used correctly
Memory leaksAre resource I/O streams closed
Are image resources recycled
Are list objects reused
IPC checksFrequent IPC causes jank

4. Design

RequirementItems
RobustnessBoundary condition checks
Fault tolerance
SecurityDo critical features have permission checks (root-related interfaces)
Single responsibilityA class does only one thing
Code couplingProgram to interfaces
Eliminate duplicate code
Open-closed principle

5. Key Points of Code Review

  1. Purpose of Code Review
    Code quality, better communication, backing each other up, technical atmosphere, cultural continuity

  2. How to Do Code Review

  • Essential elements
    • Coding conventions
    • Review guidelines
  • Execution points
    • Persist consistently
    • Summarize and optimize
    • Incentive mechanisms
    • High-quality submission
    • Efficient review

WeChat Official Account
WRITTEN BY
WeChat Official Account