Written by: Dluck
Cover: GitHub Official Blog
The code we write while programming usually exists in plain text format before compilation. Therefore, we can actually use any text editor to write code, including the built-in Notepad of the system. However, good tools can make us more efficient. When facing complex tasks, we need productivity tools like an IDE (Integrated Development Environment). An IDE is essentially a more advanced text editor that integrates many user-friendly features to enhance efficiency, such as: auto-completing variables, suggesting a list of functions that may be used, syntax highlighting, displaying syntax errors, etc.
IDEs are also constantly evolving. My first programming language was Java, and I used Eclipse, where the auto-completion feature was quite rudimentary, limited to symbol prompts and menus; I didn’t have a concept of how powerful an IDE could be. Later, after I started learning development frameworks, I gradually came into contact with JetBrains’ IDEA. The suggestions in IDEA are more intelligent; for example, you can type ‘.for’ after an array to automatically create a foreach loop, and you can use shortcuts to automatically generate getters/setters, constructors, overloaded functions, etc. Undoubtedly, JetBrains products have brought higher efficiency to coding work, providing more comprehensive and intelligent completion features.
Recently, advancements in AI technology have given code completion a significant upgrade. The GitHub Copilot we are introducing next is an AI-based code completion tool.
What is GitHub Copilot
GitHub Copilot is an AI tool developed in collaboration between GitHub and OpenAI that can help you automatically generate code you might need while editing.
GitHub Copilot can extract code context and provide suggestions for completing entire lines of code or entire functions. It can help us accomplish the following tasks:
-
Transform comments into code;
-
Automatically fill in repetitive code;
-
Write tests;
-
Quickly discover alternative solutions to problems;
-
Quickly explore new APIs without needing to search online;
-
Adapt to the way users write code, helping them complete work faster.
What is the principle?
First, let’s introduce GPT-3. GPT-3 (Generative Pre-trained Transformer 3) is an AI model developed by OpenAI for processing natural language. GPT-3 is trained by reading almost everything that is human-readable, and theoretically, it can accomplish any task that can be done through language, achieving results very close to human performance. Experiments have shown that GPT-3 can be used for writing articles, answering questions, generating code applications, designing forms, developing games, and converting textual descriptions into functional web pages, among others.
OpenAI Codex is an AI model designed for programming that is based on GPT-3. Codex learns from public code repositories, with its code sources including public code repositories on GitHub. The original text from the official site is as follows:
OpenAI Codex is a descendant of GPT-3; its training data contains both natural language and billions of lines of source code from publicly available sources, including code in public GitHub repositories.
Finally, GitHub Copilot is a commercial product developed using Codex. GitHub packages the algorithm and distributes it as a plugin and web application. GitHub Copilot now supports integration into IDEs like Visual Studio Code, Visual Studio, and JetBrains Rider through plugins for our use.
Usage & Experience
To use GitHub Copilot, you first need to register for a GitHub account. Once you have an account, you can find and enable GitHub Copilot by following these steps:
1. Find the settings page: Click on your profile picture in the upper right corner of any page, then click “Settings.”
2. Find the GitHub Copilot settings page: In the sidebar under “Code, Planning, and Automation,” click “GitHub Copilot.”
3. Enable GitHub Copilot: On the GitHub Copilot settings page, click “Enable GitHub Copilot.”
4. Choose a payment method (monthly/yearly): GitHub Copilot can be tried for free for 60 natural days, after which a subscription is required at $10/month. If you are a student, you can enjoy educational discounts and use GitHub Copilot for free.
Setting up in Rider IDE
-
Install the GitHub Copilot Plugin in preferences;
-
Restart the IDE;
-
Log in to GitHub to complete verification.
After the setup is complete, the IDE will prompt that you can use “Tab” to auto-complete code and use “⌥ + ]” or “⌥ + [” to choose other candidates for completion.
How is the experience?
While writing code, GitHub Copilot automatically suggests possible completion options, and pressing “Tab” completes the suggestion.
Sometimes, the AI does not provide a complete suggestion all at once; for instance, the code shown is not generated in one go, but rather auto-completed line by line, ultimately generating a usable function (including comments). The example below draws a ray in Unity3D to detect if there are items ahead, with only the first comment written by me.
The following example is interesting: when I tried to write the pitch of a musical score as an array, GitHub Copilot also provided what it understood as music:
In such cases, for repetitive pop music segments, GitHub Copilot can sometimes provide good answers. For example, when I pre-enter a repetitive segment from “Canon,” GitHub Copilot often completely and correctly fills in the score. This shows that when facing highly repetitive feature development or using some common algorithms, relying on AI completion is a very reliable choice. However, if the requirements are very complex, in most cases, it cannot independently provide a perfect solution. The GitHub team found in a benchmark test on a set of Python functions that after ten attempts, it could provide the correct answer about 57% of the time. In some cases, GitHub Copilot also produces code that cannot be compiled.
Disadvantages of GitHub Copilot
After using GitHub Copilot for a long time, Reddit user Colin Eberhardt pointed out several shortcomings:
-
GitHub Copilot often does not respond quickly enough. Although it has become fast enough to provide answers in seconds, this is still not sufficient for programmers who need to output quickly. Either its suggestions have not appeared before you continue typing, or you pause your thoughts waiting for it.
-
GitHub Copilot always automatically suggests. This automatic suggestion can conflict with input: sometimes when you want to wait to see what it suggests, content keeps popping up and disappearing. Perhaps the automatic mode is not the “best way to use” GitHub Copilot?
-
The quality of code generated by GitHub Copilot is insufficient. It can meet most simple and repetitive functional needs, but for skilled programmers, it may require extra effort to verify whether the automatically generated code is correct.
Copyright Issues with GitHub Copilot
Many people have pointed out that GitHub Copilot may use copyrighted code as prompt content (see Jacob Crume’s article “GitHub Copilot is Now Available for All and Not Everyone Likes It”). The author of the minority report 100gle in “GitHub Copilot: The Revolution is Not Over, The Future is Promising” has provided many examples. The most famous is that if you type Fast inverse square root
in the editor, you will get a piece of code that is identical to the algorithm used in “Quake.”
Modern open-source software often uses the GPL (GNU General Public License) agreement, which requires you to also open-source your code and use the GPL agreement. However, when using GitHub Copilot for completion, we are not sure of the license specified by the author of that code. The main purpose of open-source licenses is to restrict the use, copying, modification, and republishing of software. Clearly, using AI completion can undermine this.
It is foreseeable that, like the various controversies faced by today’s AI drawing tools, GitHub Copilot will also struggle with copyright issues, making it difficult for large enterprises to use, at least in the short term.
Usage Recommendations
-
GitHub Copilot can help beginners quickly learn common interface calling methods and simple implementation schemes when facing programming languages or development frameworks they are not familiar with. This means we can avoid repeatedly searching API manuals for some basic issues or experiencing the layers of portals on technical blog sites like CSDN.
-
GitHub Copilot can help us quickly get started in unfamiliar areas; with just some comments, it can quickly generate parts of business logic and then be tested. Of course, the final reliability of the code still needs to be discerned and controlled by the developer.
-
GitHub Copilot can significantly improve efficiency in repetitive tasks. For example, if you need to write a large number of unit tests that cannot be generated in bulk through copy/paste while needing to handle some subtle logical variations. Or if you need to develop some repetitive functions, such as declaring some data types dozens of times. In such cases, the code completed by GitHub Copilot is often very reliable.
Conclusion
GitHub Copilot may not embody the notion that “AI will soon replace programmers,” but it is undoubtedly a good helper for programmers today. As an assistant, its suggestions are not intelligent enough to allow users who do not know programming to complete development, but it is not just a simple prompt tool. Proper use of GitHub Copilot can greatly aid developers’ learning and growth.
At the same time, it inevitably has some defects, and the copyright issues of the code also limit its commercial application prospects. Less skilled programmers may also be disappointed with it—just like its name suggests, GitHub Copilot is more like an excellent co-pilot, but the work still requires an excellent driver to lead.
The best travel boots have been delivered to us; what kind of path we take still needs the developers to decide.
*The content of this article reflects the author’s independent views and does not represent the position of indienova. Please do not reproduce without authorization.