When You Have to Use LLMs to Program, Unfortunately
Over the last few months especially, I find myself frequently asked an awful a lot of questions about using LLMs to help program. My first instinct was to glibly say “don’t use them”, it which is fine especially for all the ethical reasons and environmental reasons… but unfortunately for many people who are stuck with jobs that they need in order to pay the rent, this is not an option.
Realising that what could really help me given how often I was getting asked these questions, was to actually know the limitations issues and advantages of using AI from a practical perspective. I decided to bite the bullet and give it a go. (I tried Claude, ChatGPT and Gemini for various test projects, seeing how they went working from scratch and adding or changing things to existing codebases.)
There’s a lot I could say about the experience of using AI to program (most of it bad), but the main thing I wanted to do was give two bits of advice I could give to people who have no choice but to use it for work:
1: Airgapping
Firstly: do not connect it directly to your code base if you can avoid it. LLMs are hard to predict. They sometimes do things you don’t ask them and can often garble up your code in unexpected ways or randomly add or remove things. Under no circumstance should these bullshit generators be given access to your files, and ideally not your actual code (except maybe header files, uploaded to them individually so they can read it without accessing your code repository).
Another advantage to not directly connecting the LLM up to your code is that you are forced to integrate what it produces yourself. Without direct integration, you have to copy the code out of the chat window, place it in the file, and hook it up to your the project.
This means that you are forced to see how the code works, at the very least by seeing its methods and interfaces while you’re in the process of hooking them up.
2: Reading Glasses & Bug Finding
The second piece of advice would be this: read every line of code it produces. Pretend the LLM is The New Guy. Some intern you’re working with. It’s code coming from someone who may not very experienced and has little experience working within your codebase or for your company.
If you treat it this way, your other job is to not only look at the generated code that’s been put into your project, but to perform a code review, just like you would with a junior.
Your “feedback” may not improve the LLM, but it will at least help you stay atop of what you’re putting in the project, and ensure you aren’t putting garbage in there. That way, when getting your corporate-mandated LLM to fix a bug for you, you aren’t just saying “uhm that doesn’t work, like, fix it ’n stuff” you can instead say something like:
“The input code isn’t working as expected. I think your bug is in the function parseLines() in myFile.cpp:135. I think you’re incorrectly iterating over the data, meaning its missing lines.”
The very worst thing you can do is just paste code into a project and then see if it “seems to work”. Even if it doesn’t have any apparent bugs right away, there can and often will be minor issues what the code which could cause issues further down the line.
These are the kind of things senior programmers doing code reviews for junior programmers should be catching - and your “junior programmer” being spicy autocomplete doesn’t change that fact.
Bonus: Rocket Science
And for a third bonus bit of advice:
Never ask an LLM to program something that you don’t know how to do yourself. Something you’ve done at least once. Writing boilerplate code to load data in a specific way or do a basic heatmap or something may be so easy you’re bored of doing it, but if you’ve never used a certain library or data format… always do it yourself first.
It’ll make vetting generated code easier later on, and mean you’re actually learning more.
Code Coda
I’m kinda glad I spent some time kicking the tires of LLMs. I can’t imagine myself using them with any frequency (for all the ethical reasons, environmental reasons, and just because it takes half the fun out of coding), but at least I feel a bit more genuine giving advice about their use (or abuse, or mis-use) now.
Anyway, sorry you’re forced to use LLMs to code at work, and I hope your upper management gets replaced soon so you can go back to not hating your job.