Refactor for readability prompt template

Refactor a piece of code to be clearer and easier to maintain while preserving its exact behaviour, with a short explanation of every change.

Free to copy3 fill-in variablesWorks with any text-based AI model

Copy the prompt

Keep the instruction intact and replace each double-braced field with your own context.

Refactor for readability
Refactor this {{language}} code for readability and maintainability without
changing its observable behaviour.

What the code does: {{context}}

```{{language}}
{{code}}
```

Constraints:
- Keep the public interface (function names, signatures, return values) the same
  unless I explicitly approve a change.
- Prefer clear names, smaller functions, early returns, and removing duplication
  over clever one-liners.
- Do not add new dependencies or change the algorithm's complexity unless it
  fixes a real problem - if you spot one, call it out separately.

Output, in order:
1. The refactored code as a complete block.
2. A bullet list of the changes you made and why each improves readability.
3. Anything you deliberately left alone and the reason.

If you are unsure whether a change preserves behaviour, leave the original and
note your uncertainty instead of guessing.

Fill in the variables

Use the examples as a shape, not as required wording.

{{language}}
Language of the code being refactoredExample: TypeScript
{{context}}
A one-line description of what the code is supposed to doExample: filter active users and return their display names
{{code}}
The code to refactorExample: function f(u){let r=[];for(let i=0;i<u.length;i++){if(u[i].active==true){r.push(u[i].first+' '+u[i].last)}}return r}

Filled-in example

This shows the template with realistic inputs before it is sent to a model.

              Refactor this TypeScript code for readability and maintainability without
changing its observable behaviour.

What the code does: filter active users and return their display names

```typescript
function f(u){let r=[];for(let i=0;i<u.length;i++){if(u[i].active==true){r.push(u[i].first+' '+u[i].last)}}return r}
```

Output the refactored code, a bullet list of changes and why, and anything you
deliberately left alone.

            

How to use this template

Three checks keep the result useful and grounded in your actual task.

  1. Give it real context.Replace every variable and remove any instruction that does not apply.
  2. Run it in your preferred model.The template is plain text, so it works with ChatGPT, Claude, Gemini, and local models.
  3. Review before you rely on it.Check facts, code, claims, and sensitive information; then save the wording that performed best.