Refactor a Legacy Function into Smaller Units

Break a large legacy function into small, testable pieces using Copilot.

category:refactoring
clean-code
legacy-code
workflow
multi-step
0

Prompt

A structured workflow for refactoring a massive function into smaller composable helpers without changing behavior.

## Steps:

1. Open the large legacy function and add a comment noting that it must be broken down.

2. Ask Copilot: "Identify logical sections in this function and propose names for helper functions."

3. Extract each section into a new pure function.

4. Ask Copilot: "Generate unit tests for the new helper functions."

5. Run tests and ensure behavior is preserved.

6. Remove dead code and unused variables.

7. Document the new modular structure.