code translation
Code translation converts source code from one programming language to another while preserving functionality. **Approaches**: **Rule-based**: Syntax mapping rules, limited to similar languages. **LLM-based**: Models trained on parallel code understand semantics, generate target language. **Transpilers**: Specialized tools (TypeScript to JavaScript, CoffeeScript to JavaScript). **Model capabilities**: GPT-4/Claude handle many language pairs, specialized models like CodeT5 for translation. **Challenges**: Language paradigm differences (OOP vs functional), library mapping (standard libraries differ), idiom translation (natural code in target language), edge cases and language-specific features. **Use cases**: Legacy modernization (COBOL to Java), platform migration, polyglot codebases, learning new languages via comparison. **Quality concerns**: May produce non-idiomatic code, could miss language-specific optimizations, testing crucial. **Evaluation**: Functional correctness (does translated code work?), compilation success, test suite passing. **Best practices**: Translate incrementally, maintain comprehensive tests, review and refactor output, handle dependencies separately. Valuable for migration projects.