GitHub Copilot: Deep Dive into an AI Assistant | Dice.com Career Advice

This post was originally published on this site.

Artificial intelligence (AI) has reached a saturation point where every developer needs to make use of it, or at least consider integrating it into their current workflows. Among the most popular types of AI are chatbots and code completion tools built into IDEs, including VS Code and GitHub Copilot.

If you’re using a popular IDE, and you want to be a developer, you must learn Copilot. (There are other competing tools you’ll probably want to learn, too, especially Amazon’s Q for Developer.) Let’s take a deep dive into Copilot and find out how you should direct your learning and practice.

What is Github Copilot?

GitHub Copilot is an AI tool created by GitHub in conjunction with OpenAI, the maker of ChatGPT. It’s a plugin for various IDEs, including VS Code, Visual Studio, JetBrains, and even a fork of Vim called Neovim. It includes a chat and a code autocomplete feature, and it functions essentially as a second person in a paired programming scenario, helping write code, answer questions about code, and making use of other code files. The code generation aspect alone makes it well worth it.

Important note: Copilot is not free. There’s a free trial available, but after that it’s $10 per month for an individual license or $19 for a business license. (The individual and business are nearly identical, except the business one includes user management.) There is also an enterprise one for $39 per month, which includes additional integrations with repositories in GitHub. If you’re learning software development, the $10 per month will be well worth it.

What should you learn and practice?

AI is still quite new for many developers, and many are still learning how best to incorporate tools such as GitHub into their development processes. Where should you begin?

Your best bet is to start by reading case studies. Don’t brush these off as just marketing fluff. They give you real insight into how large organizations are putting tools like Copilot to use. For example, this case study talks about how Duolingo’s team of 300 developers has started using Copilot.

GitHub also has some videos you’ll want to watch, and you can find the official documentation here (note the menu on the left of that page, especially the section called “Use GitHub Copilot”). Now let’s look at what features of Copilot you should practice on:

Get comfortable with Copilot’s user interface

There are multiple ways to interact with Copilot; one is from within the code editor itself by pressing Ctrl+i, which opens a small pop-up; another is through a dedicated chat window. Practice interacting with both until you start to develop a routine for when to use which option.

Next, learn to use all the available commands in Copilot. Copilot commands start with a forward slash. To see all the available commands, press a forward slash, and a popup window will appear listing them; the names are generally self-explanatory. Practice each command several times until you’re comfortable using them.

Then meet the participants! Yes, you read that right. Copilot consists of multiple “participants,” each with its own area of expertise. The participants have names, each starting with an “@” symbol, and you can “call on them” by typing their name with the at symbol”

  • @workspace: This is for interacting with your code that’s loaded into the IDE. Various slash commands interact here, such as /fix for fixing code.
  • @vscode: Use this when you want Copilot to interact with the IDE itself (in this case, VS Code). For example, you can type @vscode followed by a question such as “How can I search across multiple files?” When you ask a question like this, the Copilot’s chat will even include buttons to help you. For example, Copilot’s answer to my search question includes steps to configure the search in the user settings, followed by a button labeled “Show in Settings Editor.”
  • @terminal: This is for asking for help with the terminal window inside the IDE.
  • @github: This is for asking for help about how copilot can interact with GitHub.

Practice prompting Copilot to generate code

Although you can get going pretty quickly right after installing Copilot, you’ll need to be aware of all its nuances, which means keep practicing. Fortunately, it’s easy to get started. For example, I started building a node.js application that uses MongoDB along with a library called Mongoose for building data models. I created a folder called model, and in that folder I created a file called user.js. Because I’m already familiar with Mongoose, I clicked the Copilot prompt button and asked it to “import mongoose.” It then generated the correct line. I started typing a line to build my schema for a User database collection, and Copilot filled in the line for me. It made more suggestions as I built the whole file.

Then, in a different file called “department.js,” I took a different approach. This time, I simply typed “Generate a mongoose schema for department” for the prompt and it added everything I needed for a Department schema; it made assumptions about the schema itself and what fields to include.

Try something like this yourself, such as building a class called Department in your language of choice; modify the prompt to see if you can get it to build exactly the fields or members you need. Copilot is familiar with a lot of libraries and frameworks from different languages and how to use them; but the programmer needs to know this material, too.

Practice reviewing the generated code

When I created the Department schema, Copilot’s generated code was a little different from what I wanted. In such a case, you can either have Copilot redo it, or you can modify the code yourself. Try this several times and start to become familiar with what Copilot’s code looks like and how closely it matches the code you actually need. Treat this like a true code review.

Practice asking Copilot to modify the code

I asked Copilot to modify the department to include a description. It did so, but in a strange way, adding additional code at the very end of the file rather than modifying the lines of schema code directly. I undid that change and instead simply started typing the change myself inside the schema, at which point Copilot quickly caught up to what I was doing and suggested the correct change, which I accepted by simply pressing Tab.

But it turns out the first approach would have worked if I had simply positioned the cursor at the top of the schema code. It’s important to learn these kinds of quirks well ahead of any critical moments (such as during a live coding challenge at a job interview).

Practice prompting Copilot to generate comments

Copilot can generate comments in your code. By default, Copilot assumes you want your comments to look like traditional documentation-style comments, such as listing the field names followed by descriptions, much like you would see in API or framework documentation.

But Copilot can also generate comments that are more friendly; all you have to do is ask. Again, this takes practice to learn what prompts provide what types of comments. Here’s what I typed: “Please add a comment at the top of this file that explains in English what the file does.”

Practice asking Copilot to explain code and concepts

Sometimes you just want to find out what parts of the code do. For example, the generated Mongoose code calls a Mongoose method called Model. I highlighted that line, opened the prompt, and typed “What does this line of code do?”

Copilot responded with, “This line of code defines a model called Department using the Mongoose library in JavaScript.” It followed that with two more paragraphs that went into further detail. The response even included clickable links to the Mongoose documentation.

This can be useful if you’re learning a new framework. I followed the question with, “How would I then query the database for a department?” and it gave a quick description in the chat. It also provided some sample code demonstrating a query, and offered me the option to insert the code or discard it.

But note that there’s more than one way to ask Copilot to explain the code. Instead of typing what I did, I could have simply highlighted the lines of code typed “/explain” in the prompt. (But by asking the question specifically, you can have more precise control over what you want explained.)

Practice asking Copilot to verify that your comments and code match

Copilot is great with both human languages and computer languages. This means you can ask it to verify if your comments and code match. For example, you might have a code file with no comments, and separately a specification document. You can paste the spec into a comment block in the code file, and then ask Copilot if the spec and code match.

Try purposely making a mismatch between your code and your comments; highlight both, and ask Copilot, “Please check if the comments and code match.” When I tried this, it got it right every time.

Practice generating unit tests

First, a word of caution. Make sure you follow proper Test Driven Development (TDD) procedures: you start with a detailed comment of what a function does, and then you build the test code (which Copilot does for you) and then you build the function. You don’t start with the function and no comments. Here’s an excellent article that shows exactly how to use Copilot to create test cases. As usual, practice this procedure over and over with your own functions and methods until you have it down.

And More

Copilot is a huge tool, and as such we’ve barely scratched the surface here. For example, you can use Copilot in the GitHub command-line interface (CLI). To do so, you have to install it separately for the CLI. Then you can access it in the shell by typing “gh copilot.”

Copilot also offers many features that work together with repositories stored in GitHub; unfortunately, this requires an Enterprise subscription. Depending on your budget, you might want to pay the $39 for one month so you can learn it.

As you work on your own personal projects, use Copilot continuously. Not only will your personal projects benefit, but you’ll also gain valuable skills that you can demonstrate in the next interview and after you land the next job.