How to convert code with GitHub Copilot, can AI really help?

Recently, someone asked me an interesting question: "Can GitHub Copilot or AI help me convert an application from one language to another?" My answer was a definitive yes! AI can not only help you write code in a new language, but it can also improve team collaboration and bridge the knowledge gap between developers who know different programming languages.

Setting Up the Environment

To demonstrate this capability, I decided to convert a COBOL application to Java—a perfect test case since I don't know either language well, which means I really needed Copilot to do the heavy lifting. All the code is available on GitHub.

The first step was setting up a proper development environment. I used a dev container and asked Copilot to help me build it. I also asked for recommendations on the best VS Code extensions for Java development. Within just a few minutes, I had a fully configured environment ready for Java development.

Choosing the Right Copilot Agent

When working with GitHub Copilot for code conversion, you have different mode to choose from:

  • Ask: Great for general questions (like asking about Java extensions)
  • Edit: Perfect for simple document editing (like modifying the generated code)
  • Agent: The powerhouse for complex tasks involving multiple files, imports, and structural changes

For code conversion projects, the Agent is your best friend. It can look at different source files, understand project structure, edit code, and even create new files on your behalf.

The Conversion Process

I used Claude 3.5 Sonnet for this conversion. Here's the simple prompt I used:

"Convert this hello business COBOL application into Java"

Copilot didn't just convert the code, it also provided detailed information about how to execute the Java application, which was invaluable since I had no Java experience.

The results varied depending on the AI model used (Claude, GPT, Gemini, etc.), but the core functionality remained consistent across different attempts. Since the original application was simple, I converted it multiple times using different prompts and models to test the consistency. Sometimes it generated a single file, other times it created multiple files: a main application and an Employee class (which wasn't in my original COBOL version). Sometimes it updated the Makefile to allow compilation and execution using make, while other times it provided instructions to use javac and java commands directly.

This variability is expected with generative AI results will differ between runs, but the core functionality remains reliable.

Real-World Challenges

Of course, the conversion wasn't perfect on the first try. For example, I encountered runtime errors when executing the application. The issue was with the data format—the original file used a flat file format with fixed length records (19 characters per record) and no line breaks.

I went back to Copilot, highlighted the error message from the terminal, and provided additional context about the 19 character record format. This iterative approach is key to successful AI assisted conversion.

"It's not working as expected, check the error in #terminalSelection. The records have fixed length of 19 characters without line breaks. Adjust the code to handle this format"

The Results

After the iterative improvements, my Java application successfully:

  • Compiled without errors
  • Processed all employee records
  • Generated a report with employee data
  • Calculated total salary (a nice addition that wasn't in the original)

While the output format wasn't identical to the original COBOL version (missing leading zeros, different line spacing), the core functionality was preserved.

Video Demonstration

Watch the complete conversion process in action:

Best Practices for AI-Assisted Code Conversion

Based on this experience, here are my recommendations:

1. Start with Small Pieces

Don't try to convert thousands of lines at once. Break your conversion into manageable modules or functions.

2. Set Up Project Standards

Consider creating a .github folder at your project root with an instructions.md file containing:

  • Best practices for your target language
  • Patterns and tools to use
  • Specific versions and frameworks
  • Enterprise standards to follow

3. Stay Involved in the Process

You're not just a spectator - you're an active participant. Review the changes, test the output, and provide feedback when things don't work as expected.

4. Iterate and Improve

Don't expect perfection on the first try. In my case, the converted application worked but produced slightly different output formatting. This is normal and expected, after all you are converting between two different languages with different conventions and styles.

Can AI Really Help with Code Conversion?

Absolutely, yes! GitHub Copilot can significantly:

  • Speed up the conversion process
  • Help with syntax and language specific patterns
  • Provide guidance on running and compiling the target language
  • Bridge knowledge gaps between team members
  • Generate supporting files and documentation

However, remember that it's generative AI, results will vary between runs, and you shouldn't expect identical output every time.

Final Thoughts

GitHub Copilot is definitely a tool you need in your toolkit for conversion projects. It won't replace the need for human oversight and testing, but it will dramatically accelerate the process and help teams collaborate more effectively across different programming languages.

The key is to approach it as a collaborative process where AI does the heavy lifting while you provide guidance, context, and quality assurance. Start small, iterate often, and don't be afraid to ask for clarification or corrections when the output isn't quite right.

Have you tried using AI for code conversion? I'd love to hear about your experiences in the comments below! Visit c5m.ca/copilot to get started with GitHub Copilot.

References


Reading Notes #655

Welcome to the 655th Reading Notes. This edition explores embedding Python in .NET, working with stacked git branches, and an introduction to cloud-native. Plus, a quick tip for the Azure Portal and using local AI for code reviews. 

a kayak on the water with a tree at the horizon

Open Source

Programming

Cloud

AI


Sharing my Reading Notes is a habit I started a long time ago, where I share a list of all the articles, blog posts, and books that catch my interest during the week. 

If you have interesting content, share it!


~frank


Reading Notes #654

Welcome to another edition of my reading notes! This week, I’ve gathered a selection of insightful articles and resources covering topics like AI, cloud security, open source, and developer productivity. Whether you’re interested in best practices, new tools, or thought-provoking perspectives, there’s something here for everyone. 

Dive in and enjoy the highlights!

Suggestion of the week

  • Copilot, The Good Parts: Efficiency (Rob Conery) - I love that post, it's so true! There are good and bad ways to use any tools. And I personally would really like seeing Rob build his stuff. Let's him know If you think like me.

Programming

Open Source

Databases

Miscellaneous


~frank