How ChatGPT saves us hours of development time
Adam Andreasson
Lead Engineer at Palats / CEO at Komponentkoll / Maker at Ordel
If your feeds look anything like mine, you're probably drowning in posts theorising the endless possibilities of ChatGPT. Now let me share with you a real world use case.
At Palats, we are following the latest developments in AI closely and constantly brainstorming how these large models will change our industry in the near future, and how we can be a part of that.
We strongly believe that language models will be a core part of software engineering in the immediate future. We already rely heavily on Copilot, but have recently also started using ChatGPT to replace many development tasks. One of these is writing small scripts that go in our expanding toolbox. This is really where the current version of ChatGPT shines, since it only has a short term memory (context window) of 2048 words. Let me share just one example of how much time ChatGPT is saving us.
Ensuring quality of internationalisation (i18n)
We've spent the last month or so preparing Palats for a worldwide audience, which naturally starts with translating all parts of the software to English. Our first prototype software naturally started out in Swedish, but that was over two years ago, so this shift is long overdue.
The development team has painstakingly been going through all of our code the past couple of weeks, finding all strings that are hard coded in Swedish and converting them to translation keys. As with many such repetitive tasks, the engineer is often intrigued to write an automated process. But the payoff of automating something is rarely worth it if the task is a one-off. Relevant xkcd. Since we were only doing this shift once, we decided to ignore our instincts and just get it done the old school way.
Even after sifting through all of our code, basic manual tests had Swedish strings creep through in our internationalised app. Turns out, humans are not great at spending days on end just reading thousands of lines of code. If only there was a way to find strings we might have missed...
Enter ChatGPT
The task is obvious at this point. And we could spend a day or so writing and testing some tool that finds Swedish words in our codebase. The normal method is to start sketching out how such a tool would be built. But that's the old world. In 2023, we spend five minutes talking to ChatGPT.
It's a start! There are some obvious flaws in this code. The list of Swedish words that ChatGPT suggests is way too short. I point this out, and ChatGPT recommends downloading a CSV of all Swedish words from bab.la. Good idea, but I - in my imperfect human form - was not able to locate one for the life of me. Good thing I made Ordel a year ago so I already know exactly where to find a good list of Swedish words! ??
The Swedish wordlist is in txt format, so let's ask ChatGPT to change the code. And because pretty much every vowel is a Swedish word (? i ? is a valid sentence), let's make sure to skip those.
We're getting there! But a trained eye would recognise a pretty big flaw at this point. Regex is not known for it's speed, and we have a list of 400 thousand words. That's a long regex. Yeah, I didn't even dare to run this script. Let's just point this out.
领英推荐
I have no idea what a trie is. But that's the thing - I don't need to know what it is. ChatGPT explains exactly what the script does and provides pros and cons to this approach. At this point, we can test the code. It runs on the first attempt and gives us the Swedish words!
$ python test.py
['import', 'from', 'import', 'text', 'from', 'import', 'from', 'styling', 'import', 'from', 'expo', 'import', 'from', 'import', 'from', 'data', 'display', 'center', 'display', 'center', 'center', 'system', 'red', 'system', 'red', 'text', 'bokad', 'text', 'text', 'text']
It does also find a lot of false positives. Turns out, a surprising amount of words exist in both the English and Swedish language. In this file, the only word that I would consider a true positive is "bokad". Let's ask ChatGPT to address this. In this prompt, I have manually (wtf?) adjusted the file a bit to fit our purposes better, so I send ChatGPT the full script.
Great! At this point, our work is pretty much done. The last part is just adding some finishing touches by asking ChatGPT to loop through a directory, load the word list from the web, and make the output a bit prettier.
Pro tip: I'm especially a fan of this prompt addition, which speeds up the output - and subsequent feedback loop - significantly: "Reply only with the necessary changes, not the whole file".
After adding a hundred or so ignored words, the output is easily manageable. The script helped me locate a dozen files containing strings I had missed. (A pretty low number in my humble opinion!)
There we are! ChatGPT wrote a really powerful little script in minutes and with very little back-and-forth. And this was all using the free GPT 3.5 version! Check out the full conversation here.
Are there already tools out there that solve this exact problem? Maybe. The point is, using ChatGPT helped us bypass the old process of trying different search queries, installing software, reading documentation. We got exactly what we asked for. And this is just one example of dozens of instances where ChatGPT has already sped up our work. What a time to be alive!
If you like this post, maybe you would enjoy working with us! We're always looking for talented software engineers. At Palats, we are hard at work defining commercial reuse of furniture and materials, eliminating waste and carbon emissions. Feel free to send me a message!