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 :

```[LANGAGE_SOURCE]
[CODE_A_CONVERTIR]
```

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

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Similar Prompts

💻DeveloppementAdvancedClaude

Debug a Production Error

Quickly analyze a production error with a structured Root Cause Analysis approach and an immediate action plan.

47153
💻DeveloppementIntermediateClaude

Create an Accessible React Component

Create fully accessible React components meeting WCAG 2.1 with keyboard navigation, ARIA, and screen reader support.

26148
💻DeveloppementIntermediateAll AIs

Design a Complete REST API

Design a robust and well-structured REST API with OpenAPI documentation, error handling, and security best practices.

41157
💻DeveloppementIntermediateAll AIs

Generate Complete Technical Documentation for Your Code

A complete prompt to generate structured and professional technical documentation, adapted to the target audience and project type.

0106