Bringing Old Code to Life with AI! 🌸
If you have old code that is collecting dust somewhere, give that code a new lease on life thanks to AI.
Hi everybody!
Like many of you, I have increasingly found myself relying on AI assistants like Bard or ChatGPT when writing code.
Instead of rehashing some of the common coding activities we can perform using them, I want to focus in on one area that I don’t see talked about. That area is around taking old code, very likely in another language, and translating it into something more appropriate for 2024.
In this quick post, let me walk through how this helped me bring an old animation back to life.
What’s Old is New Again!
I have a huge library of code that I’ve written over the years in other languages such as ActionScript, C#, Processing, PHP, and more. This code spans email attachments, USB hard drives, and even a few Iomega Zip disks or two.
Today, all of my code (across client and server) is JavaScript, so all of that old code isn’t directly relevant. This is where AI comes in. It doesn’t matter whether you are using Bard or ChatGPT or something; they are all good here. To turn code from an older language into a modern language, all we have to do is provide a prompt similar to the following:
Translate the following <old language> code into <final language> and provide the code snippet as well.
Here is an example of this prompt at work where it helped kickstart my afternoon of bringing an old starfield effect to life:
Notice that the AI assistant, in this case, what is provided by Google’s IDX, provided me with a spot-on translation of Processing’s map
function (see reference) into JavaScript.
With a few more prompts, I was able to go from an old project that no longer worked because of some missing Java dependencies to something that works perfectly when viewed in our browsers (see source):
Is there a world where all I would have to do is point an AI assistant to a directory of old projects and have working modern versions of everything? Given the speed at which all of the AI assistants seem to be gaining advanced capabilities, absolutely positively YES!
Till Next Time
The impressive part of this whole code conversion thing is how well the AI assistants have been trained for it. In all cases, I found that it wasn’t just a literal syntax translation. The AI assistant understood the essence of what the original code was doing and translated it appropriately, replacing framework-specific methods with more appropriate ones. For an example of this sorcery at work, check out this ActionScript to JavaScript translation where, among many changes, an onEnterFrame
implementation was replaced with a requestAnimationFrame
-based one! 🤯
And with that, I’ll see you all next time. If you want to reach out to me, follow me on Twitter (err…X) or post on the forums.
Cheers,
Kirupa 🐙