DEV Community

Cover image for Why Use GitHub Copilot And Copilot Labs: Practical Use Cases for the AI Pair Programmer
Rizèl Scarlett for GitHub

Posted on • Updated on

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.

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.

Top comments (15)

Collapse
 
klausdonnert profile image
Klaus Donnert

If Copilot is good enough, I will be glad to pay for it.
Tabnine is billed as AI code completion. I know Tabnine does not compare to Copilot. I haven't used Copilot yet - I can't wait to try it.
I have tried the paid Tabnine but it's to wonky. For instance, I use a specific pattern for new function declarations. The first parameter is always (99.9%) preceded with the "required" keyword. Tabnine does not predict required until I get to the i so that it actually slows me down. Jetbrains built-in predictions work better without Tabnine.
Tabnine actually seems to get worse the more I use it. Not surprisingly, I've disabled it.

Collapse
 
blackgirlbytes profile image
Rizèl Scarlett

Interesting! I never heard this perspective before. Let me know how it goes!

Collapse
 
klausdonnert profile image
Klaus Donnert • Edited

Now after a month of using it, Copilot gets some things right. Let me stress that, Copilot gets some things right.
But it doesn't seem to learn about what I do. For instance, when I start a new class my first function is always

    public function init( required cfg config ){ 
        /*some code*/ 
        return this; 
    }
Enter fullscreen mode Exit fullscreen mode

Copilot never suggests this method so I type out by hand. Then at the return statement it always suggests return true; - slowing me down.
At other times when I start to declare a method by typing the letter f it will suggest the entire method body including the name but also a function body consisting of maybe 20 or 30 lines of code, all of it, unrelated to what I'm doing. Some of those times it gets the first line including the name correct, but I can't just keep that line. It's all or nothing. Of course, this slows me down.
It also frequently misspells variable names, in sql it misspells table and column names.
Meanwhile Tabnine has improved. Running both Copilot and Tabnine together is not hard because I can put Tabnine in single line mode. The enter key selects the Tabnine suggestion and tab accepts the copilot suggestion.
One of the things I like about Tabnine is in the situation where I need a new variable at the current place in the code block I'm writing. After I finish writing the current statement, including the undeclared variable, I move my cursor to the top to make the declaration - Tabnine correctly predicts the variable name. No other code completion tool that I've used does this. I use long variable names - this helps.
I expect both to get better over time.

Thread Thread
 
blackgirlbytes profile image
Rizèl Scarlett

Love this feedback. Thank you!!! I too think both Tabine and Copilot will mature with time.

Collapse
 
halimsamy profile image
Halim Samy

This was a very well discussion, I have found a lot of useful tricks and some I am already aware of!

Well done mate!

Collapse
 
adambiggs profile image
adam-biggs

GitHub Copilot certainly has its strengths and weaknesses. Here’s a roundup of key takeaways:

  • Fewer browser searches: Common functional solutions are available after a few words + Tab, and established patterns used in the most used frameworks/libraries are there, too. It’s a great time-saver.

  • Context matters: “Context” is key here. The AI considers factors like the frameworks or libraries in use, the variables in the current file, and related files and scope in order to produce better suggestions. Patterns are also considered in part of the answer as well.

  • It's best for experienced developers: Although AI assistance might look like a good learning tool, it’s not. Code suggestions are just that: suggestions. The developer needs to be able to evaluate these suggestions and choose to accept, skip, or ignore them. In order to use the tool properly, it’s necessary to know the context, logic, and expected output to make a smart (and fast) decision. Otherwise, the suggestion can create errors.

If you would like to learn a bit more about GitHub Copilot, I'd suggest checking out this article written by my colleague, Rafael: scalablepath.com/full-stack/ai-pai...

Collapse
 
blackgirlbytes profile image
Rizèl Scarlett • Edited

I agree with fewer browser searches and context matters..These are both very true, but I think it's also great for new developers. I actually find that it's a great learning tool, but it does depend on the way you learn. I say this as someone who works at GitHub and has years of experience teaching new developers. There's a skill and learning curve to using Copilot well, so I believe both experienced and newer developers will face similar problems.

That's a great article by your colleague. I will share it with the Copilot team. They will be interested in this.

I wrote this blog post months ago, so some of my thoughts that I wrote in this post have evolved. Check out a newer blog post that I wrote on the GitHub Blog: github.blog/2022-09-14-8-things-yo...

Collapse
 
mdazaman profile image
Md A Zaman

Co-Pilot is good for developers until it becomes advanced and matured (now it's at a very early stage but performing really good) and shrinks down developer job market.

Collapse
 
klausdonnert profile image
Klaus Donnert

All of my experience so far with AI is that there is no real intelligence in it. It's pretty dumb. It should be ASI, Artificially Simulated Intelligence.

Collapse
 
mdazaman profile image
Md A Zaman • Edited

Yeah agreed. But, that simulated intelligence can process and convert natural language into code. It will remove the barrier between people who knows natural language and who knows technical/programming language, which will not ever take away developers jobs fully but will shrink down the market and also devalue the developer's role in a team.

Thread Thread
 
klausdonnert profile image
Klaus Donnert

Not shrinking anytime soon.

Collapse
 
renanfranca profile image
Renan Franca

Thanks! I want to use it but I didn't because it's going to be paid after the test period. Do you know if is it going to have a free plan?

Collapse
 
dillonb07 profile image
Dillon Barnes

I'm not sure, but I have the technical preview and it would definitely be worth paying for. However, GitHub won't auto-charge you so don't worry about that if you want to use it. If/When it becomes paid, it'll probably just stop working until you purchase the plan.

Collapse
 
amruta_khandekar_5a7a1861 profile image
amruta khandekar

This was a very well discussion, I have found useful. Thanks

Collapse
 
willdkdevj profile image
William Derek Dias

Interesting!