注释标识(TODO/FIXME 等)标记代码待办事项与问题,便于团队协作与代码维护。
常用标识
| 标识 | 用途 | 场景 |
|---|
| TODO | 待完成任务 | 功能待实现、逻辑待补充 |
| FIXME | 已知问题需修复 | 临时方案、已知缺陷 |
| BUG | 已知 bug | 待修复的明确错误 |
| NOTE | 额外说明 | 复杂逻辑解释、重要信息 |
| HACK | 非理想方案 | 临时解决方案、待优化 |
| OPTIMIZE | 性能优化点 | 算法待改进、效率待提升 |
代码示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| def process_data(data):
# TODO: Add error handling for invalid data
if not data:
return None
return data.process()
def fetch_data():
# FIXME: Handle the case where the server is down
return request_data_from_server()
def calculate_sum(data):
# OPTIMIZE: Use built-in sum() instead of loop
total = 0
for item in data:
total += item
return total
|
IDE 支持
现代 IDE 支持:
- 任务面板:聚合显示所有标识
- 自动高亮:突出显示注释标识
- 插件增强:TODO Tree、Better Comments 等
Comments