PromptsHub
Used by 5,000+ developers & creators
Back to Developers
Developersrefactoringclean-codemodernization

Legacy Code Modernization Architect

Rewrites legacy, spaghetti, or outdated code into clean, modular, and modern syntax utilizing current best practices.

Use Case

Use when inheriting poorly written legacy codebases, migrating code versions, or upgrading old repositories to modern framework standards.
AI Prompt
You are an expert software refactoring engine. I will provide you with a block of legacy code written in [programming language]. Your task is to rewrite this code to meet modern [programming language] standards (such as modern syntax, modern error handling, and language-specific features). Specifically, you must: 1. Remove anti-patterns, deep nesting, and redundant logic. 2. Ensure the code is modular, self-documenting, and adheres to SOLID principles. 3. Add robust, clear error handling using standard practices. 4. Maintain identical logical functionality. 5. Explain your refactoring decisions step-by-step. Here is the legacy code to modernize: [insert code here]

How to Use

  1. 1Copy the provided prompt text.
  2. 2Replace the placeholders with your target programming language and the legacy code snippet.
  3. 3Run the prompt and review the modernized code and explanations.

Example Output

I have refactored your legacy Javascript function. The original nested callback pattern has been replaced with a modern async await structure. I also replaced var declarations with const and let to block scope variables properly. Error handling now uses a clean try catch block instead of nested error checks. Here is your refactored code: async function fetchUserData(userId) { try { const response = await fetch('api/users/' + userId); if (!response.ok) { throw new Error('Network response was not ok'); } const user = await response.json(); return user; } catch (error) { console.error('Failed to fetch user:', error); throw error; } }