Port Code to Another Language
Convert the provided code snippet from source language to target language while preserving its original functionality and business logic.
- Category
- Software Development & Coding
- Output
- Markdown
- Fields
- 3
- software-development
- code-generation
- code-structure
- technical-explanation
- best-practices
- code-review
Prompt
You are an expert software engineer specializing in cross-language migration and idiomatic code translation. Your task is to convert the provided code snippet from Source language to Target language while preserving its original functionality and business logic.
Follow these steps:
1. Analyze the original code to understand its core logic, data flow, and control structures.
2. Rewrite the code using idiomatic patterns, standard libraries, and modern conventions of Target language. Avoid literal, line-by-line translation.
3. Adapt error handling, memory management, and concurrency models to match Target language best practices.
4. Replace any language-specific or framework-dependent libraries with their idiomatic equivalents in the target ecosystem.
5. Provide a concise explanation of any non-trivial architectural, syntactic, or semantic differences between the two versions.
6. List all required dependencies, packages, or imports needed to compile and run the converted code.
Here is the code to convert:
```[original_language]
Code to port
```
Constraints:
- Use only the information provided in the code snippet. Do not invent functionality, external APIs, configuration values, or third-party libraries not implied by the original code.
- If Source language or Target language is missing or ambiguous, infer it from the syntax or explicitly state your assumption.
- If any part of the code relies on external context, missing variables, or unclear behavior, flag it in a brief "Open questions" section instead of guessing.
Output Structure:
Return your response strictly in the following Markdown format:
### Converted Code
```Target language
[fully working code here]
```
### Key Adaptations & Differences
- [bullet points explaining idiomatic changes, error handling adjustments, and library replacements]
### Dependencies & Imports
- [list of required packages, modules, or import statements]
### Open Questions (if any)
- [list of ambiguities, missing context, or assumptions made]
How to use this prompt
- Fill in the fields above. Required ones are marked with *.
- Check the prompt preview: your answers appear highlighted in place.
- Select Copy prompt and paste it into ChatGPT, Claude, Gemini or any AI assistant.
More Software Development & Coding prompts
- Bug Fix Brief for an AI AgentConvert raw bug reports into precise, unambiguous execution briefs tailored for AI coding agents.
- Caching Strategy DesignerDesign a robust, production-ready caching strategy for the specified feature, endpoint, or data flow.
- Database Schema Designer NormalizedProduce a production-ready, normalized relational schema with precise constraints, justified indexes, and practical migration guidance.
- Production Error Log TriageROLE: You are a senior on-call SRE and incident response engineer specializing in production debugging.
- Bug Diagnosis and FixYou are an expert software engineer and debugging specialist.
- Conventional Commit Message WriterROLE: You are a senior software engineer and version control specialist dedicated to maintaining clean, standardized, and highly readable Git history.