As part of the 7.14.2 release, I ran most of the source code through GPT-4. Let’s take a look at some of the changes it suggested, which of them I added to the code — and what this says about the future of programming.
What did GPT-4 find?
Let’s take a look.
- Not handling a type-assertion correctly and finding a bug in my metrics. GPT-4 found two real bugs. One bug was causing my metrics to be wrong. It suggested a fix, and I immediately changed the code since it was so obviously a bug. GPT-4 also noticed a bug in my switch statement logic. It told me that I seemed to want fallthrough behaviour, but wasn’t getting that. GPT-4 suggested fixes for all these issues, which I added. Finally, in the same commit, I made some style changes it suggested.
- Speeding up the test cycle. GPT-4 suggested that I cache my Go module dependencies when executing testing on CircleCI. I promptly made the change, and reduced by testing time by more than a minute (about 10% improvement). Quality and effective testing is really important to me, I love changes that make testing better.
- Tighten some timer handling, and reducing pressure on the garbage collector. It suggested I change my code slightly to reduce pressure on the garbage collector, as well as change how my timer code was structured. The changes were reasonable, and result in some improvements, so I decided to add them.
- Detected that I had a duplicated test. This was interesting one, obviously due to a copy-n-paste error. It suggested that I remove the duplicated test, and also make some style improvements — all of which I did.
- Found unnecessary type-assertions. I made the suggested changes to the code, which resulted in easier-to-read code.
- More suggestions to decrease garbage collection pressure. I incorporated the change — but only after I asked GPT-4 to explain why it would improve the code.
- Channel-handling improvements related to Queued Writes. GPT-4 spotted a missing unit test, which I added. It also suggested I tighten how the queues in the code are closed.
Is this the future?
It may not be the entire future, but it’s definitely part of it. The first thing that struck me about using GPT-4 with rqlite is that it’s fun. Sometimes it feels like a supercharged linter, and at other times it feels like magic.
I’ve been developing rqlite for more than 9 years. And having to write some boilerplate code before I can push out the newest feature does get toilsome over time. GPT-4 has sped up some of this work significantly, lowering the threshold for me starting new feature work. And that’s great.
I am an experienced Go programmer however. I can very quickly evaluate if its suggestions are meaningful, worthwhile and — most importantly — correct. Very occasionally it suggested something that was wrong, and I spotted it quickly.
But you know what else can be wrong? People. And as a senior engineer I need to check other’s code all the time (and they check mine!). But I do worry about relatively inexperienced programmers just copying-and-pasting code without thinking, and expecting it all to work.
But after just a month of using GPT-4 — and GitHub Copilot — I won’t go back. It’s too much fun, and too much of a productivity boost.