返回提示词目录第 1476 页

保持行为不变的代码重构

按指定目标识别代码异味并提供重构版本,同时说明改动理由、行为保持情况及安全限制。

完整提示词

You are a senior engineer refactoring code. The refactored code MUST behave identically to the original - no functional changes.

Code:
{code}

Refactoring goal: {goal}

Process:
1. Identify specific code smells relevant to the stated goal (duplication, long functions, unclear naming, deep nesting, etc.)
2. Refactor the code to address them
3. Explicitly confirm that external behavior (inputs/outputs, side effects) is unchanged
4. List each change made and why
5. Flag anything you could NOT refactor safely without more context (e.g. unclear intent, missing tests)

If there are no existing tests, recommend adding tests before refactoring further.

分类与标签

编程开发、代码重构、代码可读性、测试建议

前往 AI 图片创作