AI Code Gen Tools Need Human Developers to Produce Good Code

April 25, 2024
rubber duck floating upside down in the water

Last year, AI code gen tools made a huge splash in the software development world. Again. Someone had the bright idea that “Hey, source code is text. Maybe we can generate that!”. What started as one big offering has grown to dozens of tools to write our code for us.

These tools excite some, terrify others, and leave many wondering what is happening. To better understand these tools and what they can do, let’s examine the two main ways they’re used.

Pair Programming Without a Human

Have you ever noticed a programmer with a small toy on their desk? Maybe an action figure or a rubber duck? 🐥 Sometimes, it’s just desk kitsch; other times, it’s there so that we have an inanimate object to ask questions of. For whatever reason, externalizing a question can help us answer it. It’s so helpful that it has a name: rubber ducking.

AI-Enabled Rubber Ducking

If a mute little ducky is helpful, how much more valuable would one be that can respond? Well, it depends. If the duck is correct, all is well and right with the world. We save a bunch of time context switching out of the Integrated Development Environments (IDE). We don’t get distracted halfway through our web search for documentation to check Reddit. Big savings.

What about the unhappy path, though? What about when the duck is wrong?

The Dangers of Pairing With a Duck That’s Often Wrong

My personal experience with code gen tools is that the duck is wrong. Only some of the time, but often enough (10-15%) to be a genuine concern. Here are some failure cases I’ve seen:

  • Hallucinate API calls that don’t exist
  • Assume Python still doesn’t support switch statements
  • Ignore best practices
  • Answer questions without the context of the repository

I’ve been writing programs for over 30 years now and doing it for a living going on 20. Fixing busted and lousy code is something I’m pretty good at by now. More to the point, recognizing bad code is easy for me because of my experience.

When the duck is wrong, I know it in short order. I can push back and get to something better quickly. A failure case can be helpful for me, so long as I don’t get complacent and accept the duck without questioning it.

Most of your development staff won’t be senior, though. Some will be fresh out of college or boot camp. Do they know where to look if the tool hallucinates an API call? Can they recognize lousy code? Will they know how to rewrite it following best practices and matching the style of the existing repository?

Probably not. And that isn’t good. What’s worse is that now that they have this tool, they’ll rely on it. It provides a low-friction way of getting help. Much lower friction than asking a senior engineer for help. These tools can actually increase the amount of time that someone struggles with an issue before reaching out to a teammate and ultimately getting unstuck.

The Case of AI Code Completion

Generative tools attached to the IDE are like having a rubber duck that can talk back. When they do code completion, it’s like having a rubber duck that can pair with you and make suggestions. At first blush, this sounds great! And honestly, it can be. When it works well, it’s delightful. It doesn’t always work, though. It has the same accuracy and correctness problems as the above case and one critical new one.

Generative Tools Make It (Too) Easy to Write Lots of Code

These AI code gen tools make it so easy to write a high volume of code very quickly, and that’s what we want, right? To write lots of code? Well, yes, but also no.

There’s a principle in software development: don’t repeat yourself (DRY). Code gen tools make it easy to violate this principle because AI models lack a deep understanding of an entire system’s architecture and broader context. Plus, when code is generated in isolation to solve a specific problem, it can lead to repetitive code blocks that perform similar functions. It gets messy, verbose, and repetitive really quickly. Not ideal.

For example, I know I need to think about keeping my code DRY because I find it’s taking too long to write a function. “There has to be a more concise way; I need to refactor,” I say. Code gen tools take away the thing that trips an experienced developer’s Spidey-sense. The element of time gets skewed, and not always in a good way.

Don’t Overlook the Value of Humans!

Think of AI code completion as a sidekick, not a replacement developer. For complex, critical, and nuanced tasks like the following, human developers are indispensable:

  • Complex systems and architecture design
  • Critical business logic
  • Performance optimization
  • Maintenance and scalability
  • Security-sensitive applications

Should developers avoid generative tools altogether?

Perhaps shockingly, my advice isn’t to avoid code generation tools. Nor is it to only provide them to your most seasoned engineering staff. The failure cases of code gen tools fall into two categories—(1) reducing communication within a team and (2) introducing bad code into the repository.

There are tools for dealing with both of these problems. The technical problems are the easiest to handle.

Safeguard Against Technical Problems

These are things you should be doing already and likely are if you’re in the business of writing software.

Be Proactive About Team Communication

Social issues always take more work to solve. The first thing to ask is, “Why is it difficult for my programmers to talk to each other?”. Are people afraid of admitting they don’t know something? Do senior developers need to be incentivized to mentor juniors? Is time not allocated for that? Getting to the root of these may indicate why your teams aren’t talking more.

Code generation tools are powerful and can be quite effective for things like rapid prototyping, setting up standard data structures or basic CRUD operations, and filling out large sections of ‘boiler-plate’ code. However, before using them, you need to ensure your house (and repositories) are in order.

Unlock the Power of AI Engineering

From optimizing manufacturing materials to analyzing and predicting equipment maintenance schedules, see how we’re applying custom AI software solutions.

Explore AI-Enablement at SEP »

You Might Also Like