Fundamentals 18 min read

Effective Code Review Practices: Goals, Principles, Steps, and Real‑World Cases

This article explains the importance of code review, outlines its core objectives and basic principles, describes practical steps and a detailed checklist, shares several real‑world case studies with before‑and‑after code snippets, and discusses the benefits, metrics, and future AI‑assisted enhancements.

JD Tech Talk
JD Tech Talk
JD Tech Talk
Effective Code Review Practices: Goals, Principles, Steps, and Real‑World Cases

1. Introduction

Code Review (CR) is a well‑established practice that reduces defects, promotes knowledge sharing, and helps maintain clean, consistent code while lowering technical debt.

2. Core Goals and Basic Principles

2.1 Core Goals

Improve code quality : identify defects, performance issues, and enforce design standards.

Risk management : discover potential risks early to reduce rework and failure rates.

Facilitate knowledge sharing : encourage collaboration and collective understanding of the codebase.

2.2 Basic Principles

Focus on code quality, adhere to consistent standards, and maintain respectful, constructive communication during reviews.

3. Practical Steps and Techniques

3.1 Practice Steps

The CR workflow consists of three phases: preparation, review, and modification/completion.

3.1.1 Preparation

Before submitting a CR, developers should self‑inspect the code, run unit tests, and use static‑analysis tools (e.g., SonarLint, JD EOS) or AI assistants (e.g., Copilot, JD JoyCoder). Large changes should be split into smaller, logical commits.

3.1.2 Execute Review

During the review, concentrate on the checklist items (design, functionality, performance, observability, complexity, naming, comments, tests, style, documentation). Keep each session short; if it becomes lengthy, break the change into multiple reviews.

3.1.3 Modify and Complete

Developers address feedback, possibly iterating several times, and a reviewer with merge rights integrates the changes.

3.2 Best‑Practice Tips

3.2.1 Use a Clear Checklist

Typical checklist items include design, functional/non‑functional behavior, performance/stability, observability, complexity, naming, comments, tests, style, and documentation.

3.2.2 Avoid Perfectionism

Balance ideal solutions with practical constraints; incremental improvements are acceptable.

3.2.3 Split into Small MR/PR/Commit

Small change lists (100‑300 lines, ≤1.5 h review) reduce difficulty and risk.

3.2.4 Review Limited Code Volume

Do not review more than 300‑500 lines at once.

3.2.5 Review Early and Frequently

Early reviews catch issues sooner; integrate static checks in the IDE.

3.2.6 Maintain Respect

Provide constructive feedback and respect the author’s knowledge.

3.2.7 Measure and Improve

Track metrics such as review duration, defect density, and CR rate to continuously refine the process.

4. Case Studies

4.1 Case 1 – Exception & Concurrency Issues

Problem : Clearing a static cache before loading can lose configuration under concurrent access.

Improvement : Use an overwrite‑update approach.

public class ReverseSwitch {
private static Map<String, Boolean> multiConfigAddress = new HashMap<>();
public void setMultiConfigAddress(String multiConfigAddress){
ReverseSwitch.multiConfigAddress.clear();
// parse and populate map …
for (/*…*/){
ReverseSwitch.multiConfigAddress.put(/*…*/);
}
}
public static boolean isMultiConfigSwitch(){ /*…*/ }
}
public void setMultiConfigAddress(String multiConfigAddress){
log.info("ReverseSwitch.setMultiConfigAddress {}", multiConfigAddress);
Map<String, Boolean> newAddress = new HashMap<>();
// parse …
for (/*…*/){ newAddress.put(/*…*/); }
// overwrite update
ReverseSwitch.multiConfigAddress = newAddress;
}

4.2 Case 2 – Design & Observability Deficiencies

Problem : Hourly cache expiry causes burst RPC traffic; do‑while loop may loop indefinitely; missing logs/metrics.

Improvement : Use Redis pre‑loading, limit loop iterations, add monitoring.

@CacheMethod(key = "vrs.SpareQueryProxyCache.getAllSpareInfo",
cacheBean = "localGuavaCacheBean60m", timeout = Constants.REDIS_KEY_TIMEOUT_MINUTES_60)
public List<BaseStoreInfoDto> getAllSpareInfo(){
int pageNum = 0;
PageDto<List<BaseStoreInfoDto>> page;
List<BaseStoreInfoDto> returnList = new LinkedList<>();
do {
page = basicPrimaryWS.getBaseStoreInfoByPage(++pageNum);
if (page != null && CollectionUtils.isNotEmpty(page.getData())){
// process page …
returnList.addAll(page.getData());
}
} while (page != null && page.getCurPage() < page.getTotalPage());
return returnList;
}

4.3 Case 3 – Code Complexity

Problem : Scattered validation logic reduces cohesion.

Improvement : Consolidate validation into dedicated methods.

public void buildWaybillCodeList(AfterSaleOrderReceiveContext ctx){
List<String> waybillCodeList = new ArrayList<>();
if (canUseServiceCode(ctx)) {
waybillCodeList.add(WAYBILLCODE_PREFIX + ctx.getAfterSaleOrderReceiveDTO().getServiceCode());
} else {
waybillCodeList.add(this.preDeliveryId(ctx));
}
}
private boolean canUseServiceCode(AfterSaleOrderReceiveContext ctx){
// consolidate conditions …
return true/false;
}

4.4 Case 4 – Gray‑Release Strategy

Problem : No way to limit impact of a change.

Improvement : Add a feature‑toggle for gradual rollout.

public void setConsigneeAddress(WaybillAddress targetAddress){
if (ThreadLocalRandom.current().nextInt(1000) < ducc.getAddressMontageSwitchRate()) {
// new logic (A) with gray‑release control
} else {
// original logic (B)
}
}

4.5 Case 5 – Leveraging Tools

Static analysis revealed a logical‑operator precedence bug; fixing it with explicit parentheses improves correctness.

if (response != null && response.getCode() != 0 && String.valueOf(response.getCode()).length() > 2 &&
((KK_PARAM_PREFIX_CODE.equals(String.valueOf(response.getCode()).substring(0,2))) ||
KK_BIZ_PREFIX_CODE.equals(String.valueOf(response.getCode()).substring(0,2))))) {
throw new BusinessException(StringUtils.isNotBlank(response.getSubMsg()) ? response.getSubMsg() : response.getMsg());
}

5. Benefits of Code Review

Although the author’s team lacks precise statistics, industry data shows CR discovers 50‑60% of potential defects and influences 75% of maintainability decisions.

6. Conclusion & Outlook

CR remains a cornerstone of software quality; future AI‑assisted tools will provide context‑aware, predictive feedback, further reducing the need for manual inspection.

7. References

Google Engineering Practices Documentation: https://google.github.io/eng-practices/review/

Code Review at Cisco Systems: https://static1.smartbear.co/support/media/resources/cc/book/code-review-cisco-case-study.pdf

Wikipedia – Code Review: https://en.wikipedia.org/wiki/Code_review

software engineeringteam collaborationCode Reviewsoftware qualitybest practicesStatic Analysis
JD Tech Talk
Written by

JD Tech Talk

Official JD Tech public account delivering best practices and technology innovation.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.