
Workflow I use almost daily: turning messy code into clean, testable modules with AI.
Start with a working but ugly function.
Ask:
"Extract the business logic into pure functions and separate the side effects."
Then:
"Write unit tests for these pure functions."
Then:
"Refactor the side effects into dependency-injected functions so external calls can be mocked."
Finally:
"Add JSDoc comments explaining the why, not the what."
The reason this works: every step is incremental and verifiable. Run the code after each change. If something breaks, you know exactly where it happened.
I've used this on auth flows, data pipelines, and API clients.
Don't ask AI to "make this better."
Give it one mechanical improvement at a time.
English








