Thursday, November 23, 2023

Exploring GitHub Copilot

GitHub Copilot is a game-changer in the coding world. It’s like having a coding “genius” sitting right next to you, ready to help you at any time. Yeah, you read that right. It’s like having a very senior developer available for all your questions whenever you need them. And here's why I'm especially thrilled: As I get ready for an internal workshop on December 7th at our London office, I'm preparing a session about this very exciting topic. In the run-up to this event, I've been diving deep into GitHub Copilot's capabilities, and I’m happy to share my findings with you over this blog post.

If you want to learn more about GitHub Copilot, I recommend that you take the Microsoft learning path: “GitHub Copilot Fundamentals - Understand the AI pair programmer” that served as the primary source of content for this blog post.

What is GitHub Copilot?


In a nutshell, GitHub Copilot (going forward, Copilot) is a virtual, AI pair programmer that can help you write code faster and with less work. It works tirelessly by your side offering autocomplete-style suggestions on your code and comments. 

Research reveals that developers with access to Copilot finished their programming tasks 55.8% quicker than a control group without the AI pair programmer by their side. This demonstrates that Copilot increases developer productivity significantly and is an added value for those using it. For the full research, see The Impact of AI on Developer Productivity: Evidence from GitHub Copilot.

Copilot vs. ChatGPT


During my research, I considered whether ChatGPT can serve as an alternative to an AI pair programmer such as Copilot. At the end of the day, ChatGPT is free and user friendly, plus my colleagues might already be using it. Now, although ChatGPT is free and appealing, Copilot has more to offer for people who write code. To illustrate, I created the following comparison.

Feature

ChatGPT

GitHub Copilot Individual

Subscription cost

Free

$10/month

Primary function

Conversational AI

AI pair programmer

Availability

Web-based application, mobile app

IDEs (Integrated Development Environments)

Audience

General public, various industries

People who write code

Model

GPT-3.5, focused on natural language or code

Codex, a modified version of GPT-3, focused on code

Personal use

Yes, general usage

Yes, primarily for coding

Ease of use

User-friendly interface

Requires familiarity with IDEs

Learning and improvements

Pre-trained, continuous learning from interactions

Pre-trained, learns from code repositories and interactions


Copilot is based on the OpenAI Codex model, a programming model, that is focused on any type of programming tasks such as creating functions and fixing bugs. If you use the Copilot Chat to ask for support with preparing a dinner party, you will get the following answer: Sorry, but I can only assist with programming related questions. The focus of Copilot on programming tasks and the additional features it brings around that, makes it a strong peer to any person who writes code.

Now, if you don’t have access to Copilot, ChatGPT serves as an alternative, but it isn’t as specialized in programming tasks as Copilot.

Licenses


Copilot offers three licensing plans: Individual, Business, and Enterprise (release planned for February 2024). For more details on the different licenses and benefits, see GitHub Copilot pricing. This blog post focuses on the capabilities of the GitHub Copilot Individual plan.

How Copilot works


Copilot runs as a plugin within popular IDEs such as Visual Studio Code, Visual Studio, JetBrains, or Neovim. You can also use Copilot via GitHub Codespaces, a hosted developer environment that runs in the cloud.

When you type in your IDE, Copilot considers the context of the code already written, including comments, the filename, the file extension, and other open files in the IDE. This context goes through a proxy that filters out hate speech and personal data before it’s sent to Open AI. The AI model analyzes the context and generates code suggestions. These suggestions are displayed in the IDE in real-time, offering one or more alternatives for you to choose from. You can then modify, accept, or reject these suggestions. 

Your interaction helps Copilot provide more accurate suggestions over time as it adapts to your coding style. Copilot also uses your feedback on the suggestions to further improve the model. I’m not sure however whether this feedback loop also applies to Copilot for Business that has a major focus on data privacy.

Some practical tips 😉


During my hands-on trial with Copilot, I didn’t see the code block suggestions. A quick Ctrl + Enter (Windows) brings up the Copilot completions panel with many code suggestions. Also, you can accept a code suggestion using the Tab key (Windows). 

One special aspect that applies to Copilot, as described by Microsoft, is “Surround”. This means that Copilot uses the code you've already written—including comments, the filename, the file extension, and other open files in the IDE—to provide more tailored code suggestions. Consider opening more files in your IDE to provide extra context to Copilot.

Prompt engineering


You can't talk about successful generative AI interaction without talking about prompt engineering. The art of prompt engineering is crucial in reaching Copilot's full potential. A prompt is your instruction to the AI, and the more accurate and clear your prompts are, the better code suggestions Copilot generates. For example, using a comment like “// Create an API endpoint” isn't specific enough and can result in an output that doesn't meet your intentions. However, if you are more specific and define a clear scope, such as “// Create an API endpoint using the React framework that accepts a JSON payload in a POST request”, the output will more likely meet your expectations. Like anything in life, repeatedly practicing helps you get better, in this case, with prompt engineering. To learn more about prompt engineering, see Prompt Engineering Guide.

Summary


GitHub Copilot is more than a tool; it's the next level in programming and I wish Copilot had been there when I was an active developer. Its seamless integration into IDEs transforms it into the perfect programming “buddy” directly where you need it.

There might be many other features that I haven't explored, but I definitely loved these:
  • Code suggestion: Suggestion of one or more code alternatives that you can accept, reject, or modify. The suggestions appear when you start to write code or by writing natural-language comments that describe your intent.
  • GitHub Copilot Chat: A feature that makes difference, offering a conversational programming experience and responding to your questions with insights from your code's context and cursor position in the IDE. This helps you avoid context switching and navigating interruptions to look for support on the internet.
  • Surround: Copilot’s ability to use additional information (the code already written, including comments, the filename, the file extension, and other open files in the IDE) around a comment or code as context for the response.

I look forward to finishing my slides for the upcoming workshop and soon having a great time with my colleagues as we discuss and apply Copilot.

See more


Thanks for reading,
Jarbas