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

Fill in the details

Paste the source code you want to convert to another language.

The programming language of the original code (optional if the AI can detect it).

The programming language you want to convert the code into.

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

  1. Fill in the fields above. Required ones are marked with *.
  2. Check the prompt preview: your answers appear highlighted in place.
  3. Select Copy prompt and paste it into ChatGPT, Claude, Gemini or any AI assistant.
See all Software Development & Coding prompts