$ recombobulate _
home / tips / modernise-legacy-code-one-file-at-a-time
0
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.

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Scan Pending Changes for Security Issues with /security-review

The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.

bagwaa @bagwaa · 1 hour ago
0
Run Setup Scripts on Every Session with the SessionStart Hook

The SessionStart hook fires when any session begins or resumes, making it ideal for loading environment variables and running one-time setup scripts.

bagwaa @bagwaa · 1 hour ago
0
Write Property-Based Tests with fast-check and Claude

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.

bagwaa @bagwaa · 2 hours ago