| 场景 | 长表达式、条件分支中难懂的子表达式 |
|---|---|
| 命名 | 用业务含义命名,避免 temp1 式命名 |
Java 示例
Java 示例
// 之前
if (platform.toUpperCase().indexOf("MAC") > -1 &&
browser.toUpperCase().indexOf("IE") > -1) { ... }
// 之后
boolean isMacOs = platform.toUpperCase().indexOf("MAC") > -1;
boolean isIE = browser.toUpperCase().indexOf("IE") > -1;
if (isMacOs && isIE) { ... }