GitHub Copilot — Your AI pair programmer

Photograph by Andy Hermawan on Unsplash

GitHub Copilot is an AI software created by GitHub and OpenAI to assist programmers.

As of at present, GitHub Copilot is offered as an extension for Neovim, JetBrains, and Visible Studio Code.

Regardless of being a technical preview, it “does particularly properly for Python, JavaScript, TypeScript, Ruby, Java, and Go, however it understands dozens of languages and will help you discover your manner round nearly something”, as reported on GitHub Copilot.

Usually talking, in case you are into information science, internet improvement, and extra broadly software program, you need to do that out.

GitHub Copilot extension on VS Code
GitHub Copilot extension on VS Code

In short, GitHub Copilot does two issues:

  1. It can robotically counsel some code it’s possible you’ll wish to use whilst you kind. Press tab to just accept it.
  2. If you’re not pleased with the primary suggestion, preserve typing or press Alt + ]to see the following suggestion. If Alt + ]doesn’t work you may need the identical keyboard shortcut utilized by different extensions. E.g. Jupyter extensions may use Alt + ]. Nonetheless, you possibly can change shortcuts. In VS Code go to the menu beneath File > Preferences > Keyboard Shortcuts. (Code > Preferences > Keyboard Shortcuts on macOS).

Facet notice: I added a abstract of the shortcuts on the finish of the submit.

I began by making an attempt out some examples proposed within the documentation. In accordance with the docs:

  1. Create a brand new JavaScript (.js) file.
  2. Kind the next operate header:
operate calculateDaysBetweenDates(start, finish) {

and certain sufficient, GitHub Copilot robotically steered a complete operate as within the documentation:

GitHub Copilot automatically suggested an entire function
That is actually what I’ve received, so I’m utilizing the screenshot from the documentation

Okay, too good and too simple.

I adopted too many guides the place every thing was sunshine and rainbows till the second I took a step out of the steered path.

A stroll within the neighborhood

I then typed the next:

operate calculateDaysBetweenDates(start, finish) {

because the identify suggests I want to get the variety of days between two dates.

That is much like the earlier operate and I’d anticipate it to work simply wonderful. Certain sufficient, I received the next operate:

Cool, however nonetheless very simple, in my view.

The context, in check.js, may be very clear, and the identify of the operate too.

Simply above this operate, I had the earlier operate calculateDaysBetweenDates.

A stroll into the wilderness

I made a decision to attempt one thing fully out of context.

When folks begin to code they often create features that output an space, or a quantity, given some variables. So I merely typed:

operate getVolume(

and booooooooom

Photograph by Jeff Kingma on Unsplash

The end result was much less explosive however absolutely exhilarating:

A lot hype for copy-pasting lol.

Truly, this opens the bottom for one thing you need to be conscious of.

GitHub Copilot is educated on public GitHub repositories of any license! GitHub itself admits {that a} small portion of the code may be copied verbatim.

I seen.

Because of this, they received a submit titled GitHub’s automatic coding tool rests on untested legal ground on The Verge.

In that case, a developer who was making an attempt GitHub Copilot seen that when he requested to generate an About Me web page Copilot proposed the next textual content:

“I like to be taught new issues and construct issues”

and the next code

I've a <a href="https://github.com/davidcelis"> Github</a> account

The issue is that davidcelis does exist and presently has nothing to do with Copilot!

For the time being, Nat Friedman, GitHub’s CEO, discovered an answer by declaring that “Coaching machine studying fashions on publicly accessible information is taken into account honest use throughout the machine studying group”.

And that’s all people! No worries!

Ought to I believe that, by extension, a mannequin educated on publicly accessible information will at all times be publicly accessible?

We’ll see about that.

I assume the shortage of context was the issue whereas declaring getVolume so let’s begin by giving some context.

I began by declaring a peak variable and the outcome received instantly extra fascinating:

Code snippet where I am Adding variables for context
Including variables for context

It’s a honest assumption that once we declare some measure there may be some comparable measures.

I accepted the suggestion of peak = 100 and all the next options concerning width and size!

Lastly, I attempted once more my luck calculating a quantity, with a extra appropriately named operate:

Copilot proposes a possible function given some variables
The operate is an effective one

Fairly cool! It appears there could possibly be worth on this software!

Let’s check it with some typescript then!

Typing the quantity

I began as follows

  1. Create a brand new TypeScript (.ts) file
  2. Kind the next interface:
interface Quantity  
peak:

And right here is the suggestion I obtained:

GitHub Copilot proposes the right type for my interface
Interface snippet

Fairly good! I imply, it appears fairly easy and to some extent, it jogs my memory of a mixture of typescript and Angular Language Service.

Nonetheless, it’s far more than that.

By merely accepting all of the options I shortly created an interface with the fitting sorts.

With the fitting context, Copilot offers far more than completions and hints.

Copilot completes the function declaration with types
Copilot completes the operate declaration with sorts

Issues it’s possible you’ll wish to attempt

As stated earlier, in case you are not pleased with the suggestion offered by Copilot, you possibly can see extra options with the next shortcuts

  • Present subsequent suggestion — Alt + ] or Choice (⌥) + ]
  • Present earlier suggestion — Alt + [ or Option (⌥) + [

You can also try the following shortcuts:

  • Trigger suggestion — Alt + or Option (⌥) +
  • Open ten suggestions in a separate pane — Ctrl + Enter

There are some other things worth mentioning.

Copilot “can generate entire functions from something as simple as a comment”.

Here are a few quick screenshots:

Copilot autocomplete the comment
Copilot autocompletes the comment

Not only did it change the suggestion while I was typing, but it also suggests more comments.

Copilot suggests appropriate comments
Copilot suggests appropriate comments

A few tabs and Enter later and after encouraging the shy copilot by typing const I can see this function:

Copilot suggests comments and a function that calculates the area of a rectangle
Copilot suggests comments and a function that calculates the area of a rectangle

I just started and it feels great.

Developers using Copilot on VS Code are also very positive.

As declared in the documentation, GitHub Copilot doesn’t write perfect code but “tries to understand your intent and to generate the best code it can, but the code it suggests may not always work, or even make sense”.

Despite this warning, the outcome is pretty impressive and I can’t wait to use it in some bigger and more complex applications.

There are some grey areas though.

Legal stuff…

Back to this?

Surely, this is not relevant for my applications but sure enough, some industries won’t jump on it.

Think about financial companies and generally speaking companies that handle very sensitive data.

…and security

According to some studies, GitHub’s Copilot may steer you into dangerous waters about 40% of the time.

Now the question is, would the average developer do better?

Just to be clear, GitHub declares that “GitHub Copilot may suggest old or deprecated uses of libraries and languages. You can use the code anywhere, but you do so at your own risk.

On this point, they encourage developers who find “dangerous, biased, or offensive output”, to report it to copilot-safety@github.com.

What about accessibility?

I didn’t explore that but considering that many developers consider it an afterthought, some inline suggestions might be a great starting point.

Tests

As declared on GitHub: Tests are the backbone of any robust software engineering project. Import a unit test package, and let GitHub Copilot suggest tests that match your implementation code.

It is possible to use GitHub on test files as well.

At this point, you should have no doubts about wanting to try it out.

Here are the steps you need to follow:

  1. Sign up for the waiting list to get access to the GitHub Copilot technical preview. The team at GitHub is adding developers to the preview as they increase capacity
  2. Once you receive a confirmation email from GitHub, install the extension in your IDE. In VS Code go to Extensions and search for GitHub Copilot. Do you have another IDE? Follow this guide.
  3. You will be prompted to connect your GitHub account to the extension. Authorize GitHub Copilot Plugin and you are pretty much good to go.
  4. One last thing you need to accept: the telemetry terms. You may want to read more about how GitHub Copilot collects and uses data. Otherwise, that’s it.
  • Accept suggestion — Tab
  • Dismiss suggestion — Esc or keep typing
  • Show next suggestion — Alt + ] or Choice (⌥) + ]
  • Present earlier options — Alt + [ or Choice (⌥) + [
  • Set off suggestion — Alt + or Choice (⌥) +
  • Open ten options in a separate pane — Ctrl + Enter

More Posts