Modernise Legacy Code One File at a Time
A big-bang rewrite is risky and rarely finishes. A better approach: ask Claude to modernise one file at a time, keeping the behaviour identical while updating the syntax and idioms.
@app/Services/OrderService.php
Rewrite this file to use modern PHP 8.2 syntax:
- Replace array() with []
- Add typed properties and return types where missing
- Replace null checks with the nullsafe operator (?->)
- Use match() instead of switch/case where appropriate
- Do NOT change any business logic — only modernise the syntax
Claude makes targeted, safe changes and leaves the logic untouched. Run your test suite immediately after to verify nothing broke — this workflow pairs perfectly with the TDD tip.
The same pattern works across languages and frameworks:
# JavaScript → TypeScript
"Add TypeScript types to this file without changing any runtime behaviour"
# React class components → functional components
"Convert this class component to a functional component using hooks"
# Deprecated library APIs
"Update this file to use the v3 API — the migration guide is at [url]"
For large files, ask Claude to explain its planned changes before making them — you can catch misunderstandings before any code is touched.
Modernising file by file is safer than a big rewrite, and Claude makes it fast enough to actually finish.
Log in to leave a comment.
The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.
The SessionStart hook fires when any session begins or resumes, making it ideal for loading environment variables and running one-time setup scripts.
Ask Claude to write property-based tests for your functions using fast-check — it identifies the mathematical invariants in your code and generates tests that cover inputs you'd never enumerate by hand.