Copilot Best Practices (What Not To Do)

Visual Studio Code
29 Feb 202408:43

Summary

TLDRThe video provides best practices for using Copilot efficiently. Key points include not letting Copilot entirely control coding without oversight, using inline prompts and chat features appropriately, leveraging existing slash commands before creating new prompts, clearly establishing context so Copilot suggestions are relevant, and providing feedback to help Copilot improve over time. The goal is for developers to maximize Copilot's capabilities as an assistant while retaining responsibility as the pilot directing the coding.

Takeaways

  • 😀 Copilot is meant to assist, not fully replace the developer
  • 👩‍💻 Review Copilot's code suggestions instead of blindly accepting them
  • ✈️ You are the pilot, Copilot is the copilot - it should support you, not fly the plane
  • ⚙️ Use the right Copilot features for the task, like inline chat for code prompts
  • 🔀 Don't recreate existing prompts - use slash commands for fixes and explanations
  • 🗺️ Keep relevant code selected and remove off track chat history to help Copilot's context
  • 📄 Add project files to give Copilot workspace context
  • 🔙 Use up arrow in chat to reuse previous prompts
  • 👍 Use thumbs up/down and report issues to improve Copilot over time
  • ✅ Check out more Copilot best practice videos to optimize usage

Q & A

  • What is the main purpose of Copilot?

    -Copilot is meant to be an assistant that helps developers write code faster and better by providing relevant code suggestions.

  • What are some things you should not do with Copilot?

    -You should not let Copilot write full programs on its own without reviewing the code it produces. You should also not misuse Copilot's prompting tools or forget about context when asking it questions.

  • Why is it important to review Copilot's code suggestions?

    -Copilot does not always produce correct, optimal, or secure code so it's important for developers to review everything Copilot generates before using it.

  • What is the best way to prompt Copilot when you are within code?

    -When within code, you should use inline chat to prompt Copilot rather than comments, as inline chat is more efficient.

  • How can you improve Copilot's context when conversing with it?

    -You can delete previous off-track questions, highlight code you want to ask about, and add relevant files to your project.

  • How can you navigate previous questions you asked Copilot?

    -When your cursor is at the bottom of the chat panel, you can hit the up arrow key to access your previous questions to Copilot.

  • What feedback features does Copilot have?

    -Copilot has thumbs up/thumbs down buttons to rate suggestions and an option to report issues to help it improve over time.

  • What are some common slash commands in Copilot?

    -Some common slash commands are 'fix' to fix problems in code, 'explain' to get explanations of code, and 'test' to generate tests.

  • Why should you avoid recreating prompts?

    -You should first check if a prompt already exists using the slash commands before manually recreating a prompt to be more efficient.

  • What Copilot agent is aware of your workspace context?

    -The '@workspace' agent knows details about your current project files and workspace to provide better solutions.

Outlines

00:00

😊 Don't let Copilot fly the plane

This paragraph explains that Copilot is meant to assist developers, not fully replace them. It advises against letting Copilot build entire apps by itself without review, as it does not always produce optimal, secure code. While Copilot can generate helpful suggestions, developers must still thoroughly review everything it produces.

05:01

😃 Use Copilot tools efficiently

This paragraph provides examples of efficient ways to prompt Copilot, such as using inline chat and the side panel chat. It advises against using comments to prompt Copilot. It also recommends using slash commands for common requests to avoid recreating existing prompts.

Mindmap

Keywords

💡copilot

Copilot is the name of the AI assistant tool that helps developers write code more quickly and accurately. It is compared to a copilot on an airplane - meant to assist the pilot rather than fully replace them. The video advises not to let Copilot completely take over all coding tasks.

💡misuse

The script advises not to misuse Copilot's capabilities. Just like using an inefficient tool in real life, prompting Copilot inefficiently can hinder productivity. Examples are prompting through comments rather than inline chat or side panel.

💡slash commands

Copilot has preset slash commands that allow you to conveniently execute common requests like fixing code issues or generating documentation. Using these saves time compared to manually typing out prompts.

💡context

Providing clear context helps Copilot generate optimal, relevant suggestions. Ways to manage context include removing previous irrelevant chat history, keeping related code selected when prompting, and adding project files.

💡feedback

The video recommends using Copilot's built-in feedback features to rate suggestions. This helps further improve Copilot's performance over time to provide better code recommendations.

💡ghost text

Ghost text is used to receive code suggestions from Copilot without having to manually type a prompt. The user simply types placeholder text and hits enter to get contextually relevant code suggestions.

💡inline chat

Inline chat allows prompting Copilot within the code editor itself. This is the optimal way to get code suggestions compared to side panel chat or comments which are better for conversations.

💡responsible

The video says developers remain responsible for thoroughly reviewing all code Copilot produces. So while it accelerates work, Copilot should not autonomously make critical application decisions.

💡replace

The narrator cautions not to treat Copilot as a wholesale replacement for developers' skills and knowledge. It is described as a fantastic tool for generating code suggestions, but not to be solely relied upon.

💡optimal

A key point made is that following best practices allows optimal use of Copilot - maximizing productivity, efficiency and relevance of its code recommendations.

Highlights

Copilot is meant to be an assistant, not a replacement for the developer

Don't let Copilot write code without reviewing it thoroughly

You are still responsible for checking everything Copilot generates

Let Copilot be the copilot, but you are the pilot

Use inline chat for code prompts rather than comments

Use the side panel chat for more conversational questions

Use ghost text to get code suggestions without specific prompts

Use slash commands for common requests like fixing code issues

Don't recreate prompts for requests that already have slash commands

Keep relevant code selected when prompting for context

Add project files for Copilot to consider when answering questions

Use up arrow to reuse previous prompts instead of scrolling

Use feedback features to help Copilot improve over time

Rate suggestions using thumbs up/down buttons

Report issues by clicking the flag icon above prompts

Transcripts

play00:00

Hi everyone.

play00:00

So you know that Copilot is a powerful AI system

play00:03

that helps you write code faster and better.

play00:06

But is there a right and wrong way to use

play00:10

it?

play00:11

If you want to use it optimally, the answer is

play00:14

yes, and in this best practice video I will show

play00:17

you what not to do with Copilot in order to

play00:19

use it efficiently.

play00:21

So let's go ahead and take a look.

play00:23

The first thing that I want to mention is don't

play00:26

let Copilot fly the plane.

play00:28

Copilot, as the name suggests, is meant to be an

play00:31

assistant on your flight, not a replacement for you, the

play00:34

real pilot.

play00:35

So don't ask a Copilot to build an enterprise app

play00:38

on its own, assuming success.

play00:40

It is not a substitute for your own full knowledge.

play00:43

Also, it does not always produce correct optimal secure code.

play00:48

So while it's tempting to let Copilot write a lot

play00:51

of code for you, doing so without reviewing it may

play00:54

hinder productivity.

play00:56

It's a fantastic tool for generating code suggestions, but as

play01:00

a developer you are still responsible for checking everything copilot

play01:04

generates, so it's far better to let copilot point you

play01:07

in the right direction and to help complete the code

play01:10

that you write as you write it.

play01:13

Let it be the copilot, but you are the captain

play01:15

flying the plane.

play01:16

The next point I'd like to make is don't misuse

play01:19

copilot tools.

play01:20

For example, in real life it may be possible to

play01:22

eat spaghetti with a spoon, but it's not very efficient.

play01:26

Likewise, when prompting Copilot, you want to do it efficiently.

play01:30

For example, right after line 14.

play01:32

Here, it's technically possible that I can use comments to

play01:36

prompt copilot saying something like to add product rating to

play01:40

this form in addition to the product name, price, and

play01:44

description that's already there, and when I hit enter it

play01:47

will make a suggestion.

play01:49

But this is not the most efficient way to do

play01:51

this whenever you're within code.

play01:53

If you need to make a prompt you want to

play01:56

use inline chat so I can hit command I here

play01:59

add my prompt and as you can see it makes

play02:02

a suggestion on line 15 which I can accept.

play02:06

The other way to prompt copilot is to use the

play02:08

side panel chat, but this is more use for conversational

play02:12

questions rather than a simple prompt like this.

play02:15

So something that would be more appropriate is if I

play02:18

were to add that product rating like I just did.

play02:21

I can come to chat and ask it where else

play02:26

in this app must I update if I add product

play02:31

rating to this form.

play02:33

And as you could see, it could tell us all

play02:36

the different areas in the app that we'll need to

play02:39

make additional updates and the details of that update after

play02:42

I add an input for product rating.

play02:44

Now I just use product rating as an example here,

play02:48

but we're not going to really add this.

play02:50

If we're here on line 14 and we didn't know

play02:54

that we wanted to add product rating, we can just

play02:57

use Ghost Text to get suggestions from Copilot.

play03:01

So for example, when I just hit enter, Copilot's smart

play03:04

enough to notice that, oh, you used product name, price,

play03:07

and description.

play03:08

Maybe you might want a product image and I can

play03:11

go ahead and select that.

play03:13

If I move on to the next line it will

play03:15

give me another option.

play03:17

How about product category?

play03:18

And so after using ghost text and getting some suggestions

play03:22

there, if I then decide I wanted to add product

play03:25

rating, I can go ahead and request that.

play03:28

But the point is you want to do what's the

play03:31

simplest first using ghost text inline chat and for something

play03:35

more detailed conversation wise, the chat panel.

play03:39

But definitely do not use comments for prompting.

play03:43

Something else to keep in mind is that we don't

play03:46

want to recreate existing prompts.

play03:49

So somewhere in this code here between line 14 and

play03:53

19 there's some type of issue.

play03:56

So I can ask a copilot to fix the issue

play03:59

and when I hit enter it can find the problem

play04:03

and offer a suggestion.

play04:06

And as you can see on line 16 at an

play04:09

= here.

play04:09

But a quicker way to have addressed this issue was

play04:13

just to use the slash command.

play04:15

So within Copilot I can just hit slash and as

play04:19

you could see fix was already an option.

play04:23

Propose a fix for the problems in the selected code

play04:26

and just by selecting that and hit enter I get

play04:28

prompted with a solution.

play04:30

Now, sometimes when you're prompted with solutions, there could be

play04:33

more than one solution, so make sure that you navigate

play04:36

through each one to see which is best and select

play04:39

them.

play04:39

But in this case, there's just one that I could

play04:42

accept, and it's on line 16.

play04:43

It added the equal right before the>.

play04:46

So you want to keep this in mind for common

play04:49

commands that you might ask, such as to fix the

play04:52

problem or to explain some code to write documentation or

play04:56

some tests so I could select let's say at the

play04:59

very part.

play05:00

If I was still unfamiliar with like how interfaces in

play05:04

this particular code here works, I could use the slash

play05:07

command to explain the selected area and on the left

play05:11

hand side it will explain to me how the TypeScript

play05:14

interface declaration works.

play05:16

Now, while we're in the chat panel here, I should

play05:19

also mention that the slash command also works here, and

play05:23

you have even more options than from the inline chat,

play05:26

which includes API, search, workspace, etcetera.

play05:30

So definitely make some time to get familiar with some

play05:33

of these slash commands and they will be getting updated

play05:36

as Copilot matures in order to be as efficient as

play05:39

possible without having to recreate prompts that already exist.

play05:43

Next up, don't forget about context when using Copilot.

play05:47

Context is everything, and the clearer the context is for

play05:50

Copilot, the more relevant its solutions will be.

play05:54

So there's a few things that you want to do.

play05:56

The first is that if you're having conversation with Copilot,

play05:59

particularly in the panel, and you sense that the suggestions

play06:03

that you're getting are a little bit off track, you

play06:06

can always go back up and delete previous questions and

play06:09

prompts that you've asked just by navigating up and down

play06:13

the panel and hitting the X to remove the request

play06:16

and its response.

play06:17

The other thing to keep in mind in terms of

play06:19

context is to always have the related parts of your

play06:22

code selected when giving it a prompt.

play06:25

So if I want to ask questions, let's say related

play06:28

to the add event listener, I want to have that

play06:30

highlighted.

play06:31

I could choose not to highlight it and ask Copilot,

play06:34

but it's just inefficient and it's just better to have

play06:37

it highlighted and then maybe I can come over here

play06:39

and asks it to explain it to me and there

play06:42

won't be any confusion.

play06:43

Copilot will know exactly what to explain to me in

play06:46

regards to the addevent listener.

play06:48

The other point that I'd like to mention, and as

play06:50

you can see right in the prompt, is at Workspace.

play06:54

The AT workspace agent knows about your workspace and can

play06:57

answer questions related to it.

play06:59

So solutions you get is relevant to your project, but

play07:02

not just a general technical answer.

play07:05

Another thing to point out is to add files to

play07:08

your project so that copilot takes that into consideration when

play07:12

answering questions.

play07:13

So if you know some of your questions might be

play07:16

relevant to the style sheet, make sure that that's open

play07:19

and part of your project.

play07:21

And last but not least, you can always reuse prompts

play07:24

that you've asked, and you don't need to have to

play07:27

scroll up and down to look at your previous prompts.

play07:31

If you have your cursor right at the bottom of

play07:33

the panel here, just by hitting the up arrow, you

play07:36

can navigate through your previous prompts and that also saves

play07:40

time.

play07:40

So in short, when you manage your context by keeping

play07:43

all these practices in mind, you'll definitely be maximizing the

play07:47

relevance of the solutions Copilot ends up giving you.

play07:51

And the last thing that I'd like to mention is

play07:54

to not ignore the feedback features.

play07:57

Use the feedback and rating features of copilot because it

play08:00

is constantly learning from your feedback.

play08:03

So let's say for example there was a typo over

play08:06

here and when I asked copilot for a suggestion, you'll

play08:09

notice on the right hand side of the prompt Here

play08:13

you can use the thumbs up or thumbs down button

play08:16

to rate the suggestions if you want to report any

play08:19

issues by clicking on the...

play08:21

Right above you have the option to do that.

play08:23

Doing this will help Copilot improve over time and provide

play08:26

you with better code suggestions in the future.

play08:29

That's it for this best practice video on what not

play08:32

to do with Copilot.

play08:34

Hope you found it useful and don't forget to check

play08:36

out our other Copilot related videos.

play08:39

Thanks again for watching and I will see you in

play08:41

the next one.