Skip to content
  • About Us
  • Our Services
  • Case Studies
  • Blog
  • Join Us
  • Contact Us
Cartoon of an AWS button, a robot hovering over it, flanked by avatars of Continis Stuart Slade and Mark Faiers
Stuart Slade

How Can You Use AI Pair Programming Tools To Improve Your Code?

Your guide to two of the most popular AI pair programming tools, and how to use them.

In the modern world, there are more and more languages, toolsets and libraries to learn about and keep track of when developing software based solutions. As developers find themselves in unfamiliar territory, they usually have one of two options: borrowing other people’s code (from, say, StackOverflow) or pair-programming with a more knowledgeable or experienced colleague.

In recent years, however, a new option has emerged, and—you guessed it—it’s AI-enabled. Instead of a colleague helping you along, we can now lean on AI to not only answer questions specific to our programming languages and problems, but to even write some of the code for us.

It sounds like a perfect solution, and the first step to a utopian world where software is developed by machines instead of humans, allowing us to sun ourselves on a beach somewhere instead. Is this how it is going to be, though? Can AI write code so well that it erases the need for software developers? Will a huge swathe of IT people be out of a job? We’re probably not there just yet, so in the meantime we might as well make most of these tools to help us improve our own skills and alleviate some of the cognitive load of coding.

Here we discuss AI pair programming, and consider two popular tools. We discuss the benefits and risks, and take you through what happens when we put each one to the test, so that you can decide whether this new paradigm is for you.

How AI Pair Programming Started

Artificial Intelligence (AI) has seen huge growth in the last few years. There are many tools that you use on a daily basis that are driven by Machine Learning (ML), which is simply a specific type of AI. When you log in to your Amazon account to buy, say, a book, and you search for that book, you’ll see a number of recommendations of other items that you might also be interested in. These recommendations are generated by an AI engine running an ML algorithm.

We have also seen an explosion of cloud-based services from a number of service providers, with AI a common tool for developers for things such as image recognition, speech-to-text and natural language processing (NLP).

And of course, the rise of ChatGPT has made AI mainstream, with people using it to spark inspiration for music, essays and holiday itineraries, as well as writing software.

When it comes to AI for software development, there are a number of tools designed specifically to assist, and currently the two main contenders are Amazon CodeWhisperer and GitHub Copilot.

GitHub Copilot was the trendsetter in this space and, while it feels like an oldtimer, only launched in 2021. As the current frontrunner, it has the advantage of having had more time and code upon which to base its decisions and feedback, but that does mean that sometimes you might get code that relates to older libraries, older language versions, or older frameworks or best practices.

The charmingly named Amazon CodeWhisperer is a more recent addition in this space, only launching in preview form in June 2022, and on general release in April 2023. Compared to GitHub Copilot, it produces code that is much more current, but with the downside that it has had less time to accumulate a wide variety of code on which to base its feedback. Also, as it’s geared towards AWS development it might be a little less experienced outside the AWS space.

Risks and Benefits

When it comes to the general benefits of both these tools, there are a few big ones.

Both tools:

  • have the potential to show you new ways to solve problems that you might not have considered before
  • can bring information into your code directly that you would otherwise have to look up with a search engine or other tools
  • might give junior developers a view of algorithms that they might not otherwise be aware of, and at least give them the opportunity to discuss these options with more experienced colleagues
  • are based on external code written by others, and therefore they could suggest solutions that are common in industry

When it comes to the risks of each tool, there are some not-so-serious and some very serious ones to be mindful of.

  • Copilot has more potential to use older libraries and older best practices, which could lead to vulnerabilities. You must be very aware of the code that you are accepting and any potential risks with the design and the libraries that it uses
  • Both tools are using AI/ML that pulls from other people’s code. By definition then, your code could become part of that pool of information that the AI/ML engines use to develop code for others, and that means that anything you write with these tools enabled has the potential to be visible to other unknown users on the web
  • Over-reliance on any AI pair programming tool at this stage in their maturity is risky. As we will see, although they do often produce good output there are occasions when they don’t. There is still very much a need for a ‘human-in-the-loop’ to check and refine code produced by the AI.
  • Both tools are owned and hosted by American companies. This could mean your code traversing the internet and being processed and analysed on servers in the USA and other countries. If you’re working on something that requires control over the sovereignty of the code and/or data, you should absolutely not be considering using these kinds of tools

How Do the Specifications Compare?

Specs for CodeWhisperer and Copilot have a few key differences, and if price is your priority—especially while dipping your toe in the AI pair programming water—then CodeWhisperer has the edge with a free individual-user licence. You can still use Copilot for free for 30 days, but you’ll need a credit/debit card, which will be charged if you don’t cancel at the end. CodeWhisperer also includes some other useful features such as code security scanning which has a free tier of 50 scans per user per month.

Supported Languages

  • CodeWhisperer: C, C++, C#, Go, Java, JavaScript, Kotlin, PHP, Python, Ruby, Rust, SQL, Scala, Shell Scripting, TypeScript
  • Copilot: C, C++, C#, Go, Java, JavaScript, PHP, Python, Ruby, Scala, Swift, TypeScript

Pricing

  • CodeWhisperer: Individuals - Free!  Professional - $19 per user per month
  • Copilot: Individuals - $10 per month/$100 per year, Business - $19 per user per month.

Supported IDEs

  • CodeWhisperer: Amazon SageMaker notebooks, JupyterLab, AWS Toolkit for Visual Studio Code, AWS Toolkit for JetBrains, AWS Cloud9, AWS Lambda.
  • Copilot: JetBrains IDEs, Vim/Neovim, Visual Studio, Visual Studio Code; Note: Copilot is not currently available for use with Visual Studio for Mac.

Before You Try AI Pair Programming

If I can offer you two tidbits of advice before you get started it’s the following:

Be patient

The first thing to understand is that you need to be patient with these tools. They have to make network connections across the internet for any work they need to do, and this, plus the processing, takes time. To get the best out of them, you’ll want to type the questions or things that you wish to use as a prompt, and wait. If you keep typing, maybe because you think that nothing is happening, the tools will continue to wait until you stop. You could get very frustrated thinking that they don’t work, when you are not giving them time to think. You’ll know when they’re thinking because Copilot spins its little icon and CodeWhisperer has a little tick next to its name in the status bar that starts spinning, so don’t rush them.

Ask them to write some code for you

Let’s be honest, this is probably the main reason you want to use these tools. The perception is that you can use them to write code that you don’t know how to write yourself or to write in a language you’re unfamiliar with while you just act as supervisor. If that is what you are hoping for, I’m afraid you will be disappointed.

How To Use GitHub Copilot and AWS CodeWhisperer

So how do we use these tools? Here’s a brief guide to how to get started, assuming that you’re running VS-Code as your IDE.

Installation

Download the plugins from Visual Studio MarketPlace and follow the instructions. You can use these links to download GitHub Copilot and AWS CodeWhisperer.

For GitHub Copilot, If you don’t already have a licence, sign up for a free trial—you’ll need to enter your credit or debit card details, but you should be able to avoid being charged by ensuring that you cancel your subscription before the end of the first month.

When signing up, you’ll need to decide whether to block suggestions that match public code. For this investigation I chose to allow that option to give the widest possible range of suggestions. You will also have to choose whether you wish to allow Copilot to use your code or not.

To finalise the configuration of VS-Code you will need to follow the instructions here. You should receive an email that will give you a set of links to useful pages for how to set everything up.

AWS CodeWhisperer

For AWS CodeWhisperer, you’ll need a Builder account and to follow the instructions to:

Open the AWS extension panel and select the Start button under Developer Tools > CodeWhisperer. In the resulting pop-up, select the Sign in with Builder ID option. Use your email address to sign up and sign in with your AWS Builder ID.

Working Examples

In this section we will look at trying similar scenarios in both tools to see how effective they are, and how useful the results might be. Before we can start, we need to enable one of the tools to see what it can do.

With Github Copilot, there is an icon in the bottom right of your window which you can use to enable and disable the tool. With AWS CodeWhisperer, you can get to the equivalent option from the left hand toolbar.

(NB I have not tried to enable both at the same time, and I suspect that things might get a little crazy if you try. I would not recommend it)


Assuming that you have one of the tools enabled, open a new document, choose your language—in these examples, we’re using Rust but you could try similar things in other languages—and then type a comment that has a description of what you want to achieve. The tool will then try to analyse that comment and make a suggestion below as to what you might like to try.

CodeWhisperer

Let’s follow a very simple example in AWS CodeWhisperer:

Initially, upon pressing enter you get another comment saying “and so on”. Obviously not what we were looking for, so we’ll give it a little nudge by typing enum and see what that gives us.

After a short wait (remember that we have to give it time), we see that we get a greyed out prompt that completes the line. We can press the tab button to accept that suggestion and we get this:


After pressing the enter button, the suggestions continue to appear, line by line, and we can accept them one at a time by pressing tab and enter.

After a few lines, we get this:

Not very useful. The tool hasn’t really given us anything that we didn’t already give it, other than to recognise that a name of “Suffix” is better than “Suffixes”. It has offered us a number of empty comment lines, but clearly they are of no use to us at all.

Let’s manually close the enum and see what CodeWhisperer wants us to do next. After a few more tab and enter presses we see that CodeWhisperer gets stuck and leaves us with this:

It’s not a terrible suggestion, but might not be what we wanted to do at all. We cannot blame the tool for this, as we gave it nothing to go with, so we have to assume that this is what it would see as the most common use-case.

Copilot

Let’s try the same thing with Copilot. We start with the same comment, but immediately we see a different response. The second line it offers is again a comment, but very different:

If we continue, we get lots of comments with all sorts of suggestions for functions. For now though, we’ll nudge it in the same way by starting the line with an enum prompt.

In this case you can see that we get a sensible and complete suggestion, but also that we get the entire enum definition in one suggestion, not line-by-line. This might be something that you might prefer:

If we continue allowing Copilot to drive and just accept what it gives us, we get this:

Again, this looks much better but this one comparison happens to lean towards Copilot, but you will find that each tool has strengths and weaknesses.

Balancing the books


As an example, I wrote a random military rank and name generator, and Copilot initially wrote poor code for the random selection using the length of the enum (in terms of entries) and then indexing an array of enums to get the item. Also, when I asked it to generate random names, it came up with this code:


This is truly terrible, and when I ran that on my laptop I got this output:

That is, quite clearly, not much use to anyone.

I also tried a different version of the salutation idea with Copilot and got the following:

It went crazy and then died.

I tried the military salutation problem with AWS CodeWhisperer and ended up with some quite reasonable code, albeit not handling the random selection part that I had tried to encourage it to do:

The output was also quite reasonable, if a little useless:

Captain
John is a Colonel


Summary

So should you jump right into AI pair programming with both feet? Absolutely! Well, maybe start with one foot. Both tools we've discussed are very capable of generating some valid and useful code for you, but they’re not a shortcut to knowledge. You really need to understand the language you are using so as not to get caught by some very poor, and even crazy, suggestions.

When used appropriately, AI pair programming tools can really speed up your work, maintain flow, and ensure high quality.

Want to find out more about AI pair programming?

Join us at AWS ComSum on September 28th 2023!

Learn how to harness AI pair programming tools effectively in this invaluable workshop led by Mark Faiers and Julian Walls from Contino, and Chetan Makvana from AWS.


Mark, Julian and Chetan will take you through the current AI pair programming landscape including benefits, learnings and available tools. We’ll deep-dive into prompt engineering and Amazon CodeWhisperer, and show you how this AI pair programmer can radically speed up code development without risking quality.


By the end of the session you'll know how to:

  • use CodeWhisperer to support both your organisation and personal projects
  • write prompts to generate code in various languages
  • iterate on prompts to maximise the benefit of Amazon CodeWhisperer


Bring your laptop for this hands-on workshop.

About the speakers

Mark Faiers leads Contino’s AWS practice. He holds an MSc in Systems Security from the University of Oxford and has spoken at a range of industry events including AWS Re:invent. A seasoned technology writer with in-depth knowledge about serverless, application development and digital transformation, Mark uses his range of skills to support organisations in highly regulated industries.

Julian Walls is a principal consultant at Contino and AWS Serverless specialist, who helps operate and scale complex, high-profile national systems using AWS serverless.

Chetan Makvana is a senior solutions architect at AWS. He works with global systems integrators as well as AWS partners and customers to provide them with architectural guidance for building scalable architecture and execute strategies to drive adoption of AWS services.

Book now

More Articles

Coaching culture

How a Coaching Culture Can Help You Plug the Skills Gap In Agile Teams

6 September 2023 by Nigel Mahoney
Cartoon image of author at a desk with code snippets around him

Why Developing in Rust Can Help You Avoid Security Pitfalls

30 August 2023 by Stuart Slade
How To Get Started With Writing a Winning Business Case for the Cloud

How To Get Started With Writing a Winning Business Case for the Cloud

23 August 2023 by Ruchir Sanghavi
  • Londonlondon@contino.io