First thoughts on coding with AI

What is it like to code with AI? GitHub Copilot promotes itself as "Your AI pair programmer." A catchy phrase, isn't it? But can it actually live up to the title? And can it give our programming productivity a real boost?

Copilot is not a pair programmer

First things first, labeling "GitHub Copilot as a pair programmer" somewhat misrepresents what pair programming is all about. At best, it confuses people, and at worst, it could lead managers to discourage real-life pair programming sessions because, hey, we now have GitHub Copilot, right?

If your only exposure to pair programming has been a scenario in which a partner rapidly dictates the next few lines of code for you to type, without providing a rationale for their chosen implementation, without contemplating how their selections mesh with a future design, and without enlightening you about a novel function you've never encountered before, it's no surprise if you equate this with pair programming.

However, let's get this clear: that's not how a pair programming session should pan out. While this post isn't about the intricacies of pair programming, we need to be clear that AI assisted programming is something different, and making shallow comparisons between the two is not helpful.

Intrusively valuable

Upon my first encounter with GitHub Copilot, my reaction was a blend of "Wow, that's impressive!" and "Hold on! Let me complete my thought first!" This tool has an eagerness to help that can be a tad intrusive. To handle this, you can disable the "auto" part of its suggestion and trigger it manually via a shortcut. But should you do that? I believe not.

An AI system is there to suggest what it deems relevant or the logical next step. If you manually control when it gives a suggestion, you may miss out on some real gems. One feature that seems missing from GitHub Copilot's available plugins is a set time delay before suggesting. A controllable delay would help manage the interruptions while you're in the flow of typing.

Deceptively wrong

Let's acknowledge that there are many repeating patterns in programming. The main word here is patterns. I've found myself debugging an application due to some strange behavior, only to discover that the AI had inserted a line of code that seemed to follow a pattern but was actually incorrect.

Sure, we've all encountered code blocks with repeated patterns and thought, "This needs refactoring." But then, we often stumble upon tiny differences between similar lines. So, one must ponder a bit before extracting methods or carrying out other refactoring activities. AI makes similar errors—it recognizes patterns but sometimes gets the variations wrong.

Suggestions versus lookup

AI code assistants typically operate in two modes. The first is auto-completion as you type, and the second is generating code based on specific instructions. Unfortunately, the AI doesn't seem to distinguish much between these two modes. It suggests completions based on what you're currently writing, whether you're in the middle of a function or just beginning one.

The downside here relates to the length of the generated code and its context. The auto-completion feature can sometimes suggest entire functions, which are more often than not riddled with errors. The onus then falls on you, the programmer, to spot and correct these mistakes or reject the suggestion entirely.

This brings me to an important point: the impact on workflow. Accepting a ten-line code suggestion only to have to go back and correct it does not feel like a productivity boost. I wish there were a way to limit the size of the AI's suggestions. I'd prefer it to suggest a limited number of words while I'm typing, so the coding process could continue moving forward rather than backward.


Whenever we talk about productivity in software development, we cannot overlook Martin Fowler's iconic article Cannot Measure Productivity. So, do the current AI systems make developers more productive?

To be brutally honest, I don't know. Claims like "It made my team 10x more productive" seem misleading. We've only had access to these tools for a short while compared to the time it takes to develop and maintain a large system. Is this apparent productivity boost creating technical debt? If so, at what rate? And will the AI be capable of paying off this debt?

Despite these looming questions, I can say from personal experience that AI can be a boon if used judiciously. Consider the omnipresent Google and how it affects software development. Despite its widespread availability, there's a learning curve to using it effectively. If used without some understanding, you might end up losing more time than gaining. On the other hand, if you know how to use it, you can save a lot of time.

Reading, debugging, and learning with AI

A significant part of a developer's life involves reading code more than writing it. How does AI affect these other crucial software development tasks?

A few weeks ago, I had to comprehend a piece of TypeScript code, a language I'm not very familiar with. I fed the code to ChatGPT piece by piece, asking it questions along the way. The AI was incredibly helpful, particularly when I used the "Explain like I'm 5" option.

However, there was a catch: the code was well-tested, and I used the tests to supplement my learning. Having unit tests helped the AI to segregate cases and implementation details, which facilitated my understanding. This experience resembled a pair programming session more than simple auto-completion.

Final thoughts

As I was writing this blog post, GitHub announced Copilot's new Chat feature, which now focuses more on comprehension rather than completion. Who knows, by the time I finish writing this, there might be another announcement. This field is developing at such a dizzying pace that I've questioned the relevance of this post several times.

Is there a way back from AI-assisted software development? Will it prove to be inferior to the good old Google search? I don't think so. Although we need to address numerous issues, such as copyright, the early results indicate that AI offers an upgrade. The technology may need fine-tuning, but the demand it has generated ensures it will be a staple in every software developer's life.

Remember when IDEs and auto-completion were sneered at, with the popular belief being that "a real developer uses a bare text editor!" There's no such thing as "real developers" or demand for it, but there's definitely a need for working code. AI definitely could help us to get there faster; for this reason, I don't think AI help in software development is going away anytime soon.

Published in Jun 07, 2023