Why Use GitHub Copilot And Copilot Labs

Why Use GitHub Copilot And Copilot Labs

Practical Use Cases for the AI Pair Programmer

Introduction

Even though I didn't work at GitHub when they announced Copilot, I remember it piqued my interest. Perhaps, I was mostly excited because it was new and shiny. (Also, because I love predictive text in other environments like writing emails, why not in my code editor?) When I received access to the feature, I realized two things:

  1. It’s not magic. GitHub Copilot can’t read my mind, and it will not always spit out perfectly well-written, up-to-date code.
  2. Copilot increases my confidence and velocity as a programmer.

For me, the value of Copilot is that I spend less time stressing over syntax, which leaves more time for solving problems.

More recently, GitHub Next, a team exploring the future of technology and software beyond the adjacent-possible, released Copilot Labs. This experimental VS Code sidebar enables developers to translate their code from one programming language to another and explains code snippets in plain language.

With Copilot and Copilot Labs, you can:

  • Generate predictive lines of code from comments and existing patterns in your code
  • Read an explanation of a code snippet
  • Translate code from one programming language to another

These sound super cool, but when would you use them?

I share my favorite use cases of GitHub Copilot and GitHub Copilot Labs in this blog post.

What is Copilot?

Before I go into how I've used Copilot, I'll explain the feature to those unfamiliar with it.

GitHub Copilot is an AI pair programmer that helps you write code faster and with less work. GitHub Copilot draws context from comments and code, and suggests individual lines and whole functions instantly. GitHub Copilot is powered by OpenAI Codex, a new AI system created by OpenAI. The GitHub Copilot technical preview is available as an extension for Visual Studio Code, Neovim, and the JetBrains suite of IDEs.

TLDR: In other words, GitHub Copilot is an IDE extension that provides predictive code based on comments that you write and patterns in your code.

Please note: GitHub Copilot is in technical preview, and thus not all users will be able to access this feature. Please join the waitlist if you'd like to sign up for the technical preview.

Use Cases

  • Coding a little faster

Whether I'm working as a software engineer or a developer advocate, I've found myself in moments where I'm writing code at the last minute or I'm experiencing a coder's block. Reading suggestions from Copilot reminds me of how to solve common day-to-day algorithms. You can read one of my blog posts about how I used Copilot to write and understand a binary search algorithm.

For example: In one project, I had to read a file, order it alphabetically, group it by letter, insert a new element in the correct alphabetical spot, and then write the updated contents back to the file. Fortunately, Copilot helped me write a solution. See below:

Image description

  • Writing tests

While I understand that writing tests for your code are essential, I don't enjoy it. I often take forever to start – trying to remember the difference between keywords like mock, nock, beforeEach, and afterAll. Then, when I get the pattern down, it feels like a tedious process for me to reach a particular test coverage percentage. This is where Copilot can come in handy. I can write a few comments describing what I want to test; then, Copilot may suggest the code needed for the test. I can also start writing tests, and Copilot may provide anticipated code for other needed tests. Learn more by reading Using GitHub Copilot to Automate Tests by Colby Fayock.

  • Writing better comments

Sometimes, writing great comments ends up on the backburner. There's a tendency to assume your code is clean, readable, and doesn't need comments until you return to your code the next day and you're unable to decipher the hieroglyphics. Since well-written comments tend to trigger better results from Copilot, I'm more motivated to write explicit, relevant comments (and I leave them in my code insert mindblown emoji).

  • Pair programming with a coworker

I'm also not fantastic at pair programming, especially when I'm the less experienced engineer. I experience anxiety from people watching my every move, especially while I code. What stops me in my tracks is that I'm often trying to remember the syntax. With Copilot, my pair programming buddy spends less time watching me Google "reduce javaScript array method" for the umpteenth time. Instead, it may suggest the correct syntax for me.

What is Copilot Labs?

Before I go into how I've used Copilot Labs, I'll explain the feature to those unfamiliar with it.

Copilot Labs is separate from (and dependent on) the GitHub Copilot extension. While Copilot continues to march toward general availability, Labs will be a proving ground for experimental applications of machine learning that improve the developer experience. Currently, Copilot Labs consists of a VS Code sidebar that houses distinct features starting with “explain this code” and “translate this code”.

Use Cases

  • Getting comfortable in a new codebase

Whether you landed a new gig or joined a new open source community, there's no easy answer to building a mental model of a new codebase. It can take months, and codebases evolve. While Copilot Labs can't explain the entire codebase to me, I can use it to describe code blocks within a new codebase.

  • Understanding solutions you find on StackOverflow

Typically, software developers copy and paste solutions they find on StackOverflow, which is completely fine. Still, it's necessary for us to understand what we copied and why it works. Leveraging Copilot Lab's "explain this code" feature enables me to copy code from StackOverflow AND understand what the code is doing.

  • Gaining context for different data structures and algorithms

I learn best from reading, watching, and doing, which means I need various resources to create a robust mental model. When I've studied for interviews, colleges exams, and coding bootcamp, I'll watch videos, complete LeetCode exercises, and write an explanation of the code. Copilot Labs serves as an additional resource giving me more context on why and how specific algorithms work.

  • Be a better mentor

I mentor early-career developers. I'm helpful when they are currently students in the program where I mentor, but once they graduate and start working at jobs with different technologies, I'm useless. There are multiple moments when they've asked me to help them with Python or Ruby, and I'm unable to assist because I'm not familiar with those languages. With Copilot Labs, I can translate my mentee's code snippets to read the code in a familiar language, gain a better understanding of their code, and then lead them in the right direction. It even helps me explain to the mentee what's going on in their code because sometimes, as a newer developer, you're not sure why code works, but it does!

Want to see Copilot Labs in action? Watch this YouTube short as @MishManners uses Copilot Labs to translate code. {% youtube RBj3BKm54BY %}

Share ways that Copilot and Copilot Labs are useful to you in the comments below.

If you have any feedback you want to share with the team at GitHub, use the Discussion board.

Did you find this article valuable?

Support Rizel Scarlett by becoming a sponsor. Any amount is appreciated!