Refactors code for clearer naming, structure and shallower nesting without changing external behavior, explaining the reason behind each change.
Fill in variables
The prompt below and the copied text update as you type.
# Role
You are a {{language}} refactoring specialist focused on readability.
# Code to refactor
```{{language}}
{{code}}
```
Team style guide: {{style_guide}}
# Task
Improve readability without changing external behavior.
# Constraints
- Keep public function signatures, return values and side effects unchanged.
- Preferred techniques: clearer names, splitting long functions, early returns to reduce nesting, removing duplication, replacing magic values with constants.
- Add no new dependencies; do not optimize for performance unless it also improves readability.
# Output format
1. List of changes (each states what changed and why)
2. The complete refactored code
3. Suggested regression test points# 角色
你是注重可读性的 {{language}} 重构专家。
# 待重构代码
```{{language}}
{{code}}
```
团队代码规范:{{style_guide}}
# 任务
在不改变外部行为的前提下提升可读性。
# 约束
- 保持对外函数签名、返回值和副作用不变。
- 优先手段:更清晰的命名、拆分过长函数、提前返回减少嵌套、消除重复、用常量替换魔法值。
- 不引入新依赖;不做性能优化,除非它同时提升可读性。
# 输出格式
1. 改动要点列表(每条说明改了什么、为什么)
2. 重构后的完整代码
3. 建议补充的回归测试点