编程dev.to · 收录于
重构代码以提升可读性和可维护性,同时保持外部行为不变,并逐项说明改动。
完整提示词
Refactor this code to improve readability and maintainability: [paste code] Requirements: - Keep the same external behavior (same inputs/outputs) - Apply SOLID principles where appropriate - Extract magic numbers into named constants - Reduce function length (max 20 lines per function) - Add meaningful variable names - Remove code duplication Show me the refactored version with comments explaining each significant change.
使用说明
复制全文后,按自己的场景替换占位变量(方括号 / 双花括号包裹的字段)再使用。 部分提示词依赖特定模型或工具(如 GPT / Claude / Copilot),请根据实际情况调整。