
- Updated
Convert code from one language to another
This prompt converts code from a source language to a target language. Test the converted code, since idioms differ between languages.
Convert this code from [SOURCE LANGUAGE] to [TARGET LANGUAGE]: [PASTE CODE] Use idiomatic patterns in the target language rather than a literal translation, keep the same behaviour, and list any differences in libraries, types, error handling or performance I should test. Add brief comments where the approach changed.
Ask for a list of behaviour differences so you know what to test after converting.
Get a better result
Your code rewritten in the target language using that language’s normal patterns, with the same behaviour, short comments where the approach changed and a list of differences in libraries, types, errors and speed to test.
Asking for idiomatic code instead of a literal translation is the main line: word for word conversions run, but nobody wants to maintain them. Keeping behaviour fixed sets the rule, and the difference list tells you where that rule is most likely to break. Comments only where the approach changed keep the new code clean while still showing the reasoning.
The result is a line by line copy that feels foreign.
Fix: Ask it to rewrite the structure the way a native developer would, for example list comprehensions in Python or streams in Java, then compare.
- Integer division or rounding gives different numbers. Ask it to check every maths operation, since languages differ on division, overflow and rounding, and to add a test for each.
- A library it uses does not exist in the new language. Ask it to name the package it relies on and the version, then check that package page yourself before you install it.
For a big file, ask it to convert one function at a time with a test each, so you can run both versions side by side.
Write a small test that runs the same inputs through the old and the new code and compares the outputs.
More chat & writing prompts
See all 465 →More like this
- Make confusing code easy to readClaude · ChatGPT · Gemini
- Explain code line by lineChatGPT · Gemini · Claude
- Refactor messy code safelyChatGPT · Gemini · Claude
- Ask another creator to collaborateChatGPT · Gemini · Claude
- List the edge cases your code might missClaude · ChatGPT · Gemini



