Fundamentals 13 min read

Code Review Checklist: 20‑Word Summaries with Humorous Interpretations

The article presents a concise 20‑character Chinese mnemonic for code review, expands each keyword into practical guidelines covering validation, magic numbers, null checks, bounds, duplication, naming, performance, exception handling, logging, dependency management, thread safety, interface design, coupling, and robustness, with illustrative Java examples.

JD Tech
JD Tech
JD Tech
Code Review Checklist: 20‑Word Summaries with Humorous Interpretations

The author, a senior architect with extensive logistics system experience, shares a creative way to remember code review principles using twenty Chinese characters, each representing a key practice and accompanied by a humorous misinterpretation.

Validation (验) : All public methods must validate parameters and explicitly throw exceptions or return appropriate error codes. Java Bean Validation is recommended, and validation annotations should be used on method parameters and return values as a contract.

Magic Numbers (幻) : Avoid magic numbers by defining them as enums or constants to improve readability.

Null Checks (空) : Guard against NullPointerExceptions by placing constants on the left side of equals checks, avoiding unboxing null integers, checking collections for null before iteration, using the Null Object pattern, and employing StringUtils.isNotBlank for strings.

Bounds (越) : Validate array indices at the start of methods to prevent out‑of‑bounds errors.

Duplication (重) : Eliminate duplicate code by refactoring with appropriate tools.

Naming (命) : Follow naming conventions for packages, classes, methods, fields, variables, and constants; names should be meaningful and reflect responsibilities.

Examples of poor naming include constants like CODE_39120 and MESSAGE_39120, which are essentially magic numbers.

Loops (循) : Do not call services or perform database/network operations inside loops.

Frequency (频) : Know the call frequency of each method to assess performance impact on databases and caches.

Exceptions (异) : Handle exceptions properly; avoid empty catch blocks that only log without meaningful handling. An anti‑example shows a controller method catching exceptions, logging, and doing nothing else, which hides errors from users.

@RequestMapping(value = "/export")
public void export(CityRelationDomain condition, HttpServletResponse response) {
    ZipOutputStream zos = null;
    BufferedWriter bufferedWriter = null;
    try {
        condition.setStart(0);
        condition.setSize(MAX_EXPORT_LINES);
        List<CityRelationDomain> list = cityRelationService.getOrdersByCondition(condition);
        response.setCharacterEncoding("GBK");
        response.setContentType("multipart/form-data");
        response.setHeader("Content-Disposition", "attachment;fileName=export.zip");
        zos = new ZipOutputStream(response.getOutputStream());
        bufferedWriter = new BufferedWriter(new OutputStreamWriter(zos, "GBK"));
        bufferedWriter.write("订单类型编码,始发城市-省,始发城市-市,目的城市-省,目的城市-市");
        ZipEntry zipEntry = new ZipEntry("export.csv");
        zos.putNextEntry(zipEntry);
        for (CityRelationDomain domain : list) {
            try {
                bufferedWriter.newLine();
                bufferedWriter.write(CSVExportUtil.trans2CSV(domain.getOrderCode()));
                bufferedWriter.write(',');
                bufferedWriter.write(CSVExportUtil.trans2CSV(domain.getProvinceNameFrom()));
                bufferedWriter.write(',');
                bufferedWriter.write(CSVExportUtil.trans2CSV(domain.getCityNameFrom()));
                bufferedWriter.write(',');
                bufferedWriter.write(CSVExportUtil.trans2CSV(domain.getProvinceNameTo()));
                bufferedWriter.write(',');
                bufferedWriter.write(CSVExportUtil.trans2CSV(domain.getCityNameTo()));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        bufferedWriter.newLine();
        bufferedWriter.flush();
        zos.closeEntry();
        bufferedWriter.close();
    } catch (Exception e) {
        e.printStackTrace();
        logger.error("导出CSV文件异常");
    } finally {
        try {
            if (zos != null) {
                zos.close();
            }
            if (bufferedWriter != null) {
                bufferedWriter.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Length (长) : Split overly long lines, refactor long methods, and consider splitting large classes.

Dependency (依) : Understand external service performance metrics and define SLAs.

Reuse (轮) : Prefer mature libraries over reinventing wheels.

Thread Safety (线) : Be aware of non‑thread‑safe classes like HashMap, SimpleDateFormat, and ArrayList; avoid using mutable fields in singleton Spring services without proper synchronization.

Typical unsafe code example:

@Service
public class AService {
    private static final SimpleDateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd");
    public void doSomething() {
        // use FORMAT
    }
}

Another unsafe pattern uses a mutable member variable in a service:

@Service
public class BService {
    private Pojo b;
    public void doB() {
        b = getB();
        process(b);
    }
}

Logging (日) : Use appropriate log levels, conditionally log expensive string constructions, and prefer structured JSON logging; avoid printing directly to the console.

Bad logging example:

@Service
public class FooService {
    private static final Logger LOGGER = LoggerFactory.getLogger(FooService.class);
    public void doFooThing(Foo foo) {
        LOGGER.debug("get parameter foo {}", JSONObject.toString(foo));
        try {/*do something*/} catch (Exception ex) {ex.printStackTrace();}
    }
}

Simplicity (简) : Keep overall design and method implementations concise; use caching, Redis, or asynchronous processing where appropriate.

Interface (接) : Use interfaces to isolate variations; avoid large if‑else blocks inside a single class for different business types.

Two approaches are shown: a monolithic implementation with many conditionals, and a decoupled design using a factory and separate service implementations.

public interface BarService {
    void doBarThing(Bar b);
    void doBarFatherThing(Bar b);
}

public class BarServiceImpl implements BarService {
    public void doBarThing(Bar b) {
        if (b.getType() == BarType.A) {
            // logic A
        } else if (b.getType() == BarType.B) {
            // logic B
        }
    }
    public void doBarFatherThing(Bar b) {
        // similar conditional logic
    }
}

public class BarServiceFactory {
    public BarService getBarService(BarType type) {
        // return appropriate implementation
    }
}

The second approach separates common logic into a base class and creates type‑specific subclasses, improving decoupling and extensibility.

Coupling (偶) : Recognize tight coupling via shared data schemas; prefer interface calls or message queues for looser coupling, but avoid overusing MQ within a single system.

Correctness (正) : Enforce forward dependencies; lower layers should not depend on higher layers, and avoid circular dependencies.

Divide (分) : Apply divide‑and‑conquer by breaking complex problems into simpler sub‑problems with clear inputs and outputs.

Robustness (壮) : Ensure robustness through contracts (validate inputs early), consider edge‑case outputs, and design fallback or degradation strategies for failures.

The article concludes with a call to follow the JD Tech public account for more technical content.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Backendjavasoftware-engineeringCode reviewbest practices
JD Tech
Written by

JD Tech

Official JD technology sharing platform. All the cutting‑edge JD tech, innovative insights, and open‑source solutions you’re looking for, all in one place.

0 followers
Reader feedback

How this landed with the community

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.