Coding Prompts
Convert Code Between Languages
Translate code from one programming language to another, using idiomatic patterns for the target.
Prompt
Convert the following code from [SOURCE_LANGUAGE] to [TARGET_LANGUAGE]. **Source code ([SOURCE_LANGUAGE]):** ```[SOURCE_LANGUAGE] [CODE] ``` Requirements: - Write idiomatic [TARGET_LANGUAGE] — use the language's conventions, standard library, and common patterns. Do NOT just transliterate the source syntax line-by-line. - Where the source relies on a library or built-in that has no direct equivalent, use the most widely adopted [TARGET_LANGUAGE] library for that purpose and mention it. After the converted code, include a **"Migration Notes"** section covering: 1. Any behavior differences between the source and target versions (e.g., different error handling semantics, different numeric types) 2. Language features or libraries in the source that have no direct equivalent, and how you handled them 3. Recommended [TARGET_LANGUAGE] libraries or tools the converted code depends on (with package names)
How to Use
Paste the code you want to port and specify both languages clearly. The prompt asks for idiomatic output, not a literal translation — so a Python list comprehension becomes a Go slice loop, not a forced one-liner. Read the Migration Notes carefully since behavioral differences (especially around error handling, null semantics, and type coercion) are the most common source of bugs in ported code.
Variables
| Variable | Description |
|---|---|
| [SOURCE_LANGUAGE] | The language the original code is written in (e.g., Python, JavaScript, Java, Go) |
| [TARGET_LANGUAGE] | The language you want to convert to (e.g., TypeScript, Rust, Kotlin, C#) |
| [CODE] | The complete code snippet to convert — include any type definitions, imports, or helper functions it relies on |
Tips
- For large files, convert one function or class at a time — smaller conversions are more accurate and easier to verify before moving on.
- If the target language has multiple valid approaches (e.g., async vs. sync, OOP vs. functional), specify your preference upfront so the model doesn't have to guess.