July 12, 2023 • 6 min read

Accelerate Your Projects with Copilot: Tips for Improving Your Development Flow

Rédigé par Valentin de la Perraudière

Valentin de la Perraudière

According to GitHub, 92% of developers integrate AI tools in their development workflow. What was once a niche and unreliable technology is now becoming a valuable tool, and Copilot may be the most powerful and the simplest one to use: it just improves your development experience, without needing to change your workflow!

GitHub Copilot, powered by OpenAI's GPT language model, is an AI pair programmer, generating code suggestions in real-time based on the context of the code being written. Copilot aims to accelerate the development process by automating repetitive tasks and reducing the cognitive load on developers.

If you’re on the fence or just started to use Copilot, and you are wondering how it will improve your coding experience, just keep reading!

Setting up Copilot

But first, a few words about the setup!

If you are a student or a heavy open-source contributor, GitHub Copilot is free! Otherwise, you will have to subscribe, with a subscription cost of $10 per month ($100 a year) for a personal license, and $19 a month if using a business license (which includes additional privacy features, discussed later).

All the instructions can be found on the official website, and once you are subscribed, the integration into your favorite IDE is seamless (via the installation of a dedicated extension). Visual Studio, Neovim, VS Code, or Jetbrains IDEs are all supported!

Finally, if you’re not sure about subscribing yet, GitHub offers a 30-day free trial. Try it and see by yourself!

Efficient use of Copilot

Now that Copilot is installed, let’s see what it can do! Far from replacing an experienced developer, Copilot takes care of all the tedious stuff, to let you focus on what really matters!

This article will not oversell the wonders of AI, plenty of others already do! Instead, let’s look at a list of real, frequent work situations where using Copilot lets you gain some time (and some peace)!

1. Write a simple function from a description

Assume that you have the following data:

table containing example data of fruits bought
Fruits bought

Here is a pandas dataframe representing it:

You now want a function computing the total sold amount for each fruit.

This is one of the most obvious use cases of Copilot: you know what you want, but you are not sure about the syntax of the actual instructions.

Just formulate your request in a comment, almost as if you were googling:

# Function which takes in input a dataframe containing the purchased fruits for all customers, and computes the total amount of sold fruits (one line by fruit)

If your Copilot extension is correctly set, just go to the next line and auto-completion should offer the following solution

Which gives this result:

total aggregated by fruit
Total by fruit

This is a very simple example, but it illustrates one of the major advantages of Copilot: when in doubt, you don’t have to get out of your IDE anymore and browse the web or documentation in search of some specific syntax.

As before, when you got a tip from a StackOverflow answer, for example, you should check that Copilot’s suggestion actually does what you expected. But the feedback is instant, and customized to your use case!

Most of the time when coding a function, writing the name, signature (the list of arguments with their types), and docstring should be enough to have a very decent implementation suggested by Copilot!

And if the initial suggestion doesn’t fit your needs, you can use the CTRL + Enter shortcut to display 10 potential solutions generated by Copilot!

2. Automate repetitive tasks

This use case seems magical the first time you encounter it! Let’s assume that you have semi-structured data that, for example, a client sent by mail:

Dear XXX,
As discussed, please find the following mapping:
- EUR: euros
- DOL: $
- CAN:canadian dollar

You now need to implement this mapping in your code, but it is obviously not usable as is: the format is totally inconsistent, and even if it were, this is not a standard table format.

But just copy the mapping in your editor, and type the first example of the actual formatted mapping: Copilot will automatically generate the other ones:

In my case, I didn’t even need to give the first actual mapping, Copilot offered the right solution right after I typed “df”.

Once you are satisfied with the solution, don’t forget to remove the “helping” material.

3. Write a unit test

This one can be done in two ways: either you have written a function, and you want to test it, or you are using Test Driven Development, and started with the test and now need to implement the function.

In both cases, Copilot will do most of the work for you!

Let’s assume that you wrote this function:

You now want to test it: just type def test_n_, and it should be enough for Copilot:

Of course, the Syracuse conjecture is a very simple case, because many examples of its implementation are available in Copilot’s codebase. However, even for custom functions, the test suggested is correct:

This might not be the case for more complex/specific tests, but the solution offered is at least a good starting point.

And for data transformation tests, Copilot is very good at generating mock data to feed your tests!

Generally, Copilot takes care of the repetitive part of writing tests, like complying with a Given / When / Then template or listing test data, and lets you focus exclusively on the “smart” part of the test.

4. Write a docstring

Unlike the first use case, you may have already created functions and classes in your project, but with incomplete documentation.

Assume that you have the following function, without any docstring

You now want to add a docstring to this function, to explain its behavior and simplify future references to it.

Just open the quotes (’’’) and Copilot does the rest!

Remember that Copilot uses your already written code to better match your own programming style: if you and your team use specific docstrings conventions, Copilot’s recommendations will take them into account.

5. Call a function with the right arguments

This final example may be considered just a small improvement over standard auto-completion, but it is actually way more powerful: when calling a function, Copilot will try to autocomplete the arguments.

For example, if you defined the following constants:

Now, to call the previously defined draws_without_replacement function, just type the name of the function, and Copilot will propose arguments of the right type!

Even better, if you vaguely know that an argument exists in a function, but you ignore the possible values, try typing the argument’s name, and Copilot will make an educated guess!

We could keep listing numerous examples of the drastic improvements to the coding experience that Copilot confers, but by now I assume you got the point: Copilot is purely beneficial to the dev experience!

And it is obviously constantly improving: experimental functions (which can be tested via dedicated extensions) include applying peer-review comments directly, fixing linter warnings, or translating code from one language to another, to help you understand it.

Understanding Copilot’s usage of context

Now that we’ve seen a few examples of Copilot’s usage, let’s clarify a bit the way it works.

Copilot is based on Codex, an Open AI system, which is itself a descendant of GPT-3.

When developing and pausing your writing, Copilot will send the content of the current file, but also of related files, as a prompt for Codex. Hence, don’t hesitate to open relevant files to improve the context used in your current development.

Codex then sends back suggestions, which are displayed directly in the editor by the Copilot extension.
These prompts and suggestions are only sent in real-time unless you have chosen to enable telemetry collection, in which case they are retained.

You can configure privacy settings on this page.

Limitations of Copilot

Even if Copilot’s suggestions are often quite good, it also makes its fair share of mistakes.

Because it is trained on the existing code base, GitHub Copilot may not be as good at making suggestions concerning relatively new technologies (e.g. Polars vs Pandas) as it is for widely used tools.

Generally, it also is not very good at handling exceptions: functions with a very generic behavior can be almost entirely written with Copilot, but when you need a fine-tuned response to edge cases, you almost always need to adapt what was proposed.

And finally, like any generative AI, there is no indication of the degree of confidence Copilot has in its answers. Remember to always check the code proposed by Copilot, and make sure you understand both its logic and its design. According to GitHub itself, you should be as wary of code produced by Copilot as you are of code found on the Internet!

Concerning privacy, as stated earlier if you don’t authorize telemetry in Copilot’s settings, none of your code should be stored on GitHub’s side. However, unless you have a business license, user activity data will still be stored.

Conclusion

What remains of GitHub Copilot once the hype of generative AI and the thrill of novelty have subsided? An incredibly useful tool that makes almost every coding moment more satisfying!

It won’t replace a developer but is only the logical evolution of dev tools. Unless you refuse to use any dev assistance and only code in a text editor without autocompletion or Internet access, you won’t lose any specific competence using Copilot.

What you will gain, however, is plenty of time that you can invest in skills that matter!

At Sicara, we’re convinced that generative AI is a breakthrough and that it has the potential to deeply transform our lives! If you’re looking for AI experts, feel free to contact us!

Cet article a été écrit par

Valentin de la Perraudière

Valentin de la Perraudière