AIでレガシーコードをリファクタリングする

動作しているものを壊さずにAIを使って既存のコードを改善するための安全なステップバイステップワークフロー。

3 steps
codingdeveloper-toolsproductivity
1

変更前にコードを理解する

コードを貼り付け、AIに何をするか、どんな依存関係があるか、変更したら何が壊れる可能性があるかを説明してもらいます。

Example prompt
Explain what this code does in plain English. Identify: the purpose of each function, any side effects, external dependencies, what other parts of the codebase likely depend on this, and what the riskiest parts to change are. Code:

[PASTE CODE]
2

優先度付きリファクタリング計画を得る

AIに影響と リスクで整理したリファクタリングの改善点をリストアップさせます。低リスク・高価値の変更から始めます。

Example prompt
Suggest refactoring improvements for this code, ordered by: impact (how much it improves readability/performance/maintainability) and risk (how likely it is to introduce bugs). For each suggestion: what to change, why it's better, and any risks. Code:

[PASTE CODE]
3

一度に一つの関数をリファクタリングしてテストする

AIに一つの関数をリファクタリングさせます。各変更後にテストスイートを実行します。

Example prompt
Refactor only this single function. Preserve the existing behavior exactly — do not change what it returns or its side effects. Apply these improvements: [LIST IMPROVEMENTS FROM PREVIOUS STEP]. Show the before and after, and explain each change. Function:

[PASTE SINGLE FUNCTION]
Ready to try Emergent?
Follow this playbook with the actual tool
View Tool