lab/note/随手记/布尔变量命名.md
张育新 ef18635509 docs(note): 补充技术笔记和主题配置
- Go map Swiss Table 实现说明
- MarkText 仿 onelight 暗色主题
- 布尔变量命名规范
- 更新网址收藏及跟踪 assets 资源
2026-07-21 17:53:15 +08:00

17 lines
756 B
Markdown
Raw 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语句中会让大脑进行双重否定运算