lab/note/资源/编程/规范/布尔变量命名.md
张育新 241a7c43da docs(note): 新增 excel/正则/Nginx 笔记并整理目录
- 新增 AGENTS.md 仓库说明与 excelize 依赖
- 新增正则表达式、go操作excel、Nginx常见错误、Golang底层架构笔记
- 布尔变量命名迁移至资源/编程/规范,删除随手记旧笔记
2026-08-05 18:32:17 +08:00

17 lines
756 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 命名规则
> [《布尔变量起名的艺术》](https://thatamazingprogrammer.com/posts/stop-naming-your-variables-flag-the-art-of-boolean-prefixes/)
### 使用正确的前缀
1**is**:描述事物的状态,后面跟形容词,比如 isActiveisDeletedisEmpty。
2**has**:描述事物的所有权或包含关系,后面跟名词,比如 hasAccesshasChildrenhasValidationErrors。
3**can**:描述事物的能力或权限,比如 canEditcanDeletecanRetry。
4**should**:描述事物的意图或逻辑,比如 shouldRetryshouldCacheResponse。
### 其他
永远不在布尔变量名中使用否定词比如isDisabled因为当使用在if语句中会让大脑进行双重否定运算