Translation among Different Programming Languages

Learn how ChatGPT's code translation capabilities extend beyond natural language, enabling seamless translation between programming languages.

In the Boosting Day-to-Day Productivity with ChatGPT chapter, we learned how ChatGPT has great capabilities for translating between different languages. What is really incredible is that natural language is not its only object of translation. In fact, ChatGPT is capable of translating between different programming languages while keeping the same output as well as the same style (namely, it preserves docstring documentation if present).

There are so many scenarios when this could be a game changer.

For example, we might have to learn a new programming language or statistical tool we’ve never seen before because we need to quickly deliver a project on it. With the help of ChatGPT, we can start programming in our language of preference and then ask it to translate to the desired language, which we will be learning alongside the translation process.

Python to MATLAB translation example

Imagine that the project needs to be delivered in MATLAB (a proprietary numerical computing and programming software developed by MathWorks), yet we’ve always programmed in Python. The project consists of classifying images from the Modified National Institute of Standards and Technology (MNIST) dataset. The dataset contains numerous handwritten digits and is frequently utilized to teach various image processing systems.

To start, we write the following Python code to initialize a deep-learning model for classification:

Get hands-on with 1200+ tech skills courses.