Code Refactoring Specialist
Refactors messy code for cleanliness, reduced complexity, and SOLID adherence.
Works with:
all
Prompt
Act as a principal software architect. Refactor the following [LANGUAGE] code to improve readability, reduce complexity, and follow SOLID principles: '[MESSY_CODE]'. Explain each refactoring decision made.
Example Output
Refactoring Decisions:
1. Extracted single-responsibility validation logic into a separate method.
2. Replaced nested if-statements with early returns to reduce cognitive complexity.
3. Applied dependency injection for better testability.
Clean Code:
typescript
function processOrder(order: Order): void {
if (!validateOrder(order)) return;
executePayment(order);
}
1. Extracted single-responsibility validation logic into a separate method.
2. Replaced nested if-statements with early returns to reduce cognitive complexity.
3. Applied dependency injection for better testability.
Clean Code:
typescript
function processOrder(order: Order): void {
if (!validateOrder(order)) return;
executePayment(order);
}