laitimes

The most complete series of intelligent code completion tools in history is GitHub Copilot

author:Write bugs every day

In recent years, artificial intelligence has developed rapidly, and has been applied in all walks of life, especially in the past two years, AI development tools for developers are also emerging in an endless stream, from these tools, we see the infinite possibilities that AI can bring to developers. This series of articles mainly introduces foreign Kite, Codota, TabNine, GitHub Copilot, Microsoft IntelliCode, domestic Alibaba Cloud Cosy, AIXcoder and other programmers more commonly used intelligent coding auxiliary tools, and will do some more detailed comparative evaluation of personal use experience in subsequent articles.

PreviousWe introduced the TabNine article of the most comprehensive intelligent code completion tool series in history, in this article we take a look at a recently released tool GitHub Copilot, the official website homepage: https://copilot.github.com/

GitHub Copilot (hereinafter referred to as Copilot) is a recently released code intelligent generation plug-in, currently supports VSCode, JetBrains and other IDE platforms, unlike other code completion tools that only provide up to one line of completion results, Copilot can generate the entire code snippet through the code context and language description, which is undoubtedly the developer's coding tool. How does it do it? TabNine mentioned in the previous article of this series uses the GPT-2 deep learning model, while Copilot uses the GPT-3 model that OpenAI is said to have burned tens of millions of dollars, copilot on the basis of the GPT-3 model through learning the open source code of GitHub, got the Codex model, which has a strong code generation ability, but because the model is very large, it needs to have enough infrastructure support. So Copilot can only be tried on a small scale in the form of invitations, and the information from the FAQ shows that Copilot is unlikely to be widely available for free in the future, so developers who like the tool need to be prepared to pay for it.

Support features

  • Only the remote service model is provided, and the code needs to be uploaded to the remote end, so developers who are enterprises may have to pay attention to data security
  • Ability to generate method-level code snippets from code context, comments, and language descriptions

Official website demo

As shown in the following figure, we only need to enter the function description of the code and the method name of the code, Copilot will automatically recognize the context of the code, and wait 2~3 seconds to generate a complete method fragment.

The most complete series of intelligent code completion tools in history is GitHub Copilot

The demo example on the official website mentions three usage scenarios:

1. Generate code snippets based on code comments

The most complete series of intelligent code completion tools in history is GitHub Copilot

2. Autofill repeat code with fixed mode

The most complete series of intelligent code completion tools in history is GitHub Copilot

3. Automatically generate unit test cases, especially Mock data

The most complete series of intelligent code completion tools in history is GitHub Copilot

Usage experience

Copilot's model is very powerful, and its principle is essentially similar to TabNine, but Copilot's code generation is much better, after all, the model size is not one level. Copilot code generation results of the display form and other tools are different, it uses the way of inlining, this way is very intuitive to show the code after the generation of the look, suitable for the display of multiple lines of code snippets, but this way is not suitable for the recommendation of the results more, can only switch the results through the shortcut key, and if the automatic trigger is turned on, when writing code will often appear when I do not need to, the code being written is squeezed below, which is a kind of disturbance for my daily coding.

Let's look at a few Java examples:

1) Using the same example, Copilot can complete the entire line and automatically populate the inputStream into the parameters.

The most complete series of intelligent code completion tools in history is GitHub Copilot

2) Copilot can also automatically recognize the workflow variable and its getSheetAt method that appeared above, and there is no syntax error problem.

The most complete series of intelligent code completion tools in history is GitHub Copilot

3) Although the completion worked well in the previous example and there were no syntax errors, Copilot still generates code snippets with syntax errors in many cases. As shown in the following figure, the StringUtils class was created in the local project, there is only one readTestFile method below the class, but Copilot generated the print method, because Copilot is based on hundreds of millions of open source code to learn, can not learn the code information of the local project in time, so essentially the same as TabNine there will be syntax errors, but because the model is more powerful, so the probability of error is smaller, But when it comes to the code of the local project, the probability of errors is very high.

The most complete series of intelligent code completion tools in history is GitHub Copilot

4) Writing unit tests with Copilot is very convenient, it can help me generate a lot of test data, reduce my Troubles with Mock data.

The most complete series of intelligent code completion tools in history is GitHub Copilot

5) Copilot method-level code generation also has many errors, such as generating code that reads XML files, and the result is to read Excel code, possibly because the class starts with more Excel-related APIs.

The most complete series of intelligent code completion tools in history is GitHub Copilot

If I remove the import, then it can't be generated, only another comment based on the comment.

The most complete series of intelligent code completion tools in history is GitHub Copilot

Sometimes the code it generates gets stuck in infinite repetition, such as the dead loop that generates Insert in the following diagram.

The most complete series of intelligent code completion tools in history is GitHub Copilot

In general, GitHub Copilot is a very good code generation tool, suitable for generating common tool code, leetcode algorithm, unit tests and other scenarios of high-frequency code, and the generation of business code is still a problem of syntax errors, unfortunately Copilot only provides remote service mode, and based on Copilot's current technical route is unlikely to provide offline mode, which may bring potential privacy and code data leakage risks, Hopefully the charge won't be too expensive in the future.

GitHub Copilot for everyone to introduce here, if there is a flaw in the text welcome to correct, interested partners can in the IDE plug-in market by searching GitHub Copilot installation experience, welcome to exchange feedback in the comments. The next issue of this series will bring you Microsoft IntelliCode, so stay tuned!

Read on