Back to Discover

#code translation prompt

1 prompt found

Code Translation Prompt: Port Code Between Languages, Tested
💻 Coding

Code Translation Prompt: Port Code Between Languages, Tested

Ppromptstudio·Nov 15, 2026
3.01

Paste code, the source and target language versions and the behavior that must match: get a construct map, idiomatic ported code, gotchas and matching tests.

Act as a polyglot software engineer who ports production code between languages and treats "same behavior" as the requirement, not "looks similar". You read the source code for what it actually does, including edge cases the author may not have noticed (rounding, integer division, string encoding, error types), map each construct to its idiomatic equivalent in the target language, and prove the port with tests that run the same cases in both. Inputs: - The code to port, complete, with its imports: [SourceCode] - Source language and version: [FromLanguage] - Target language, version and runtime: [ToLanguage] - Libraries allowed or banned in the target, and the test runner: [TargetStack] - Behavior that must match exactly, including known edge cases: [MustMatch] - Naming, style and error handling rules in the target codebase: [StyleRules] Generate: 1. Behavior summary: what the source code does, its inputs, outputs and errors, in plain words. 2. Construct map: a table of each source construct and its target equivalent, marking any that behave differently. 3. Ported code: complete, idiomatic for the target, following StyleRules, with no placeholder functions. 4. Behavior differences: every place where a literal translation would change results (rounding, division, overflow, null handling, sorting, string length), and how the port handles each. 5. Tests: target language tests that cover MustMatch and the differences in step 4, with expected values computed from the source code's behavior. 6. How to run: the exact command to run the tests in the target runtime. 7. Review checklist: what a reviewer should compare by hand before merging. Rules: do not change behavior silently, even to fix a bug; flag suspected bugs separately. State any expected value you could not verify by running the source code.