P
💻DeveloppementIntermediateAll AIs

Convert Code Between Programming Languages with AI

A prompt to convert code from one programming language to another while respecting the conventions, native idioms and best practices of the target language.

Paste in your AI

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

Tu es un développeur senior expert en [LANGAGE_SOURCE] et en [LANGAGE_CIBLE]. Je vais te fournir du code écrit en [LANGAGE_SOURCE] et tu dois le convertir en [LANGAGE_CIBLE] en respectant les règles suivantes :

  1. Préserver la logique métier : le comportement fonctionnel doit être strictement identique.
  2. Adopter les conventions du langage cible : nommage des variables (camelCase, snake_case, etc.), structure des fichiers, organisation du code selon les standards de [LANGAGE_CIBLE].
  3. Utiliser les idiomes natifs : remplacer les patterns du langage source par leurs équivalents idiomatiques dans le langage cible (ex : list comprehension en Python, streams en Java, pattern matching en Rust).
  4. Gérer les dépendances : si le code source utilise des bibliothèques, propose les équivalents les plus populaires et maintenus dans l'écosystème de [LANGAGE_CIBLE].
  5. Typage et gestion d'erreurs : adapte le système de types et la gestion des erreurs aux conventions du langage cible.
  6. Commentaires : traduis les commentaires en français et ajoute des annotations là où la conversion implique un choix d'implémentation différent.

Pour chaque conversion, fournis :

  • Le code converti complet et fonctionnel
  • Un tableau récapitulatif des correspondances clés (structures, fonctions, types) entre les deux langages
  • Les points d'attention ou différences de comportement potentielles
  • Les dépendances à installer dans le langage cible

Voici le code à convertir :

[CODE_A_CONVERTIR]

Personalize this prompt with Léa

Answer 3 questions and Léa tailors the prompt to your situation.

Why this prompt works

<p>This prompt transforms the AI into an expert code translator that goes beyond word-for-word syntactic conversion. By specifying the <strong>source language</strong> and <strong>target language</strong>, you get an idiomatic rewrite that respects the conventions and best practices of each ecosystem.</p><p>The six rules govern conversion quality: preserving business logic, adopting naming conventions, using native patterns, replacing libraries with their equivalents, adapting typing and translating comments. The correspondence summary table helps you <strong>understand the conversion choices</strong> and build skills in the new language.</p><p>For better results, provide complete code rather than isolated snippets, and specify the target language version if it matters (e.g., Python 3.12, Java 21, TypeScript 5). Feel free to add context about the intended use: <strong>CLI script, web API, shared library</strong>, etc.</p>

Use Cases

Migrate a project or module from one language to another (e.g., Python to Go)Learn a new language by comparing side-by-side implementationsRewrite a quick prototype in a more performant language for productionPort an open source library to your project ecosystem

Expected Output

Complete code converted to the target language with idiomatic conventions, a correspondence table between the two languages, notes on behavioral differences and a list of required dependencies.

Learn more

Check the full skill on Prompt Guide to master this technique from A to Z.

View on Prompt Guide

Comments

Be the first to comment on this prompt.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Similar Prompts

💻DeveloppementIntermediateChatGPT

Write Integration Tests for an API

Create complete API integration tests with database setup, authentication, CRUD, and end-to-end scenarios.

29243
💻DeveloppementAdvancedClaude

Set Up Application Observability

Implement the three pillars of observability (logs, metrics, traces) with OpenTelemetry, Prometheus, and Grafana dashboards.

44239
💻DeveloppementIntermediateAll AIs

DALL-E Prompt to Generate JavaScript Code

DALL-E, the image generation model developed by OpenAI, is not designed to produce executable JavaScript code. However, it can play a valuable complementary role in a JavaScript developer's workflow. DALL-E excels at creating visuals related to development: user interface mockups, architecture diagrams, data flow schemas, or illustrations to document your code. By crafting precise prompts, you can obtain visual representations of complex JavaScript concepts like closures, the event loop, or design patterns. These visuals then serve as references for implementing your code, creating attractive technical documentation, or designing educational materials. The approach is to use DALL-E as a rapid visual prototyping tool: generate a UI mockup, then translate it into JavaScript components. This method accelerates the design phase and reduces back-and-forth between designers and developers. In this guide, we offer optimized prompts to get the most out of DALL-E in your JavaScript development process, from UI prototyping to visual documentation of your code.

018
💻DeveloppementIntermediateAll AIs

Debug Your Python Code with ChatGPT

A structured prompt to get a complete analysis of your Python bugs: identification, root cause explanation, commented fix, and prevention tips.

0209