GitHub Copilot
What is GitHub Co-pilot
Open AI Codex, a machine learning model that translates natural language into code, powers GitHub Copilot to draw context from comments and code to suggest individual lines and whole functions as you type. Codex is a version of GPT-3 (Generative Pre-trained Transformer 3) fine-tuned for programming tasks. Some of your favourite applications, like Duolingo, use GPT-3 for grammar correction.
Get Started
The easiest way to get started is to use vscode extensions.
If you’re using Jetbrains IDE, you can use this plugin.
Prompt based code-generation
All three functions have been auto-generated by the Github copilot based on prompts
- Generate random numbers between 3 & 99
- Sort an array in ascending & descending orders
Copilot Labs
GitHub Copilot Labs is vscode extension developed by Github which provides two features
- Explain this code
- Language Translation
Both of these features make it easy if you’re either learning a new language or trying to understand the existing codebase which might be complex or written in a different language than the one you’re familiar with.
Explain this code
Every developer learns that writing new code is only a part of software development. Often, the hardest job that developers face is reading and understanding code. Whether it’s because it’s an unfamiliar codebase, or whether the code in question is using a library you might not know, the first step is getting a rough idea of what’s going on, so you can jump in and use the code, or make some changes.
This feature lets you highlight a block of code and ask GitHub Copilot to explain it in plain language:
Language Translation
Language translation works similarly to the explain feature: highlight a chunk of code, select the language you’d like to translate that code into, and hit the “Ask Copilot” button.
While the translations are imperfect, they can serve as good starting points for developers who are finding logic in the wild and adapting it to their needs in another language.
Bash to python & Bassh to Java— correctly translated
Javascript to Python — Incorrect
Javascript to Golang — Incorrect
Javascript to Rust
Python to Golang — Incorrect
Gotchas
This is a snippet from my side project where I’m using TailwindCss and Github copilot is trying to give nested div
suggestions that are never-ending.
Blindfold
As you can see in my project structure, there are no lib
folders and still Github copilot suggests importing useAAuth
from ../lib/auth
Package context blindfold
package.json
file doesn’t have any firestore
library and still Github copilot is suggesting it, it should rather not suggest any imports or only imports from node packages installed.
React component suggestion
As we saw earlier, Github copilot doesn’t have context about project files, however here the intention is to see if you write the component, will it suggest the properties of that component!
Addtion
is a sample react component which will be used later by another component.
Here once you write <add
the Github copilot understands that there are two properties.
Generate the wrong pattern
As you can see below, the generated pattern by Github Co-Pilot is wrong.
Promot to create new react app
Based on the prompt create react project to serve hello world
it gave suggestions to add App.js
App.css
However, in the coming days, it should be capable enough to generate an entire project itself without giving suggestions.
Duplicate imports
Even though React
is imported, it's asking again to import which isn’t correct.
Edit & Insert
OpenAI also released Edit & Insert capabilities which you can explore here.
In Summary, Github Copilot is a powerful tool in any developer’s toolkit and in the coming days, the model is going to be even more mature and should be able to perform other tasks such as writing the application from scratch, optimizing the existing code, writing code based on eslint guidelines etc.
If you like this article, please share it and follow me on Twitter.