GitHub Copilot has attracted a lot of attention since its inception. It is needless to say that its code recommendation ability is amazing, but some subsequent problems have aroused heated discussions, including whether programmers will lose their jobs because of Copilot and the copyright of its recommended code. However, this article does not intend to discuss these points. This article is some practice of Copilot's code recommendation ability after I passed the trial application. I hope it can be helpful to you.
I roughly classify GitHub Copilot's capabilities into three types: assisted programming, text-to-code transformation, and empirical inference.
Assisted programming predicts and recommends possible codes based on the context of user input to make programming efficient. Here are some examples. The first example is the writing and comparison of the most common React components:
IProps, the recommended component code contains interface definition.
Tablecomponents, here is the recommended code:
When there is no context, Copilot can also recommend a usable code, although it is possibly not what we want. When there is a context, the recommended code is more accurate. The richer the context, the more accurate the recommendation.
Text-to-code transformation refers to the automatic generation of object code based on a description. Here are some examples:
Although it takes more time, Copilot still recommends a decent code, whether it is available or has not been verified yet.
/*@cc_on!@*/ is a unique code below ie11. Please refer to this link for more information.)
Some commonly used functions and algorithms can generate codes according to descriptions, but the accuracy of generated codes cannot be guaranteed. These codes most likely come from actual code fragments. Whether they are correct or not needs to be judged by developers. I suggest that the generated code should be for reference only. It should not be used directly in production.
Copilot can automatically find out some laws implicit in the code. It can learn personal coding habits and recommend personalized codes if it is used often. Here is an example:
Another more complicated example:
The ability is quite amazing. I guess the logic behind it is similar to code2vec, which recommends according to the similarity of text semantics.
Copilot is useful as a coding aid, but here are some tips:
⚠️ Don't rely too much on the generated code since its accuracy is not guaranteed.
⚠️ Currently, there is no local version of Copilot. Thus, the Internet is a requisite. Pay attention to the code security risk.
⚠️ Think of it as a development aid (like code completion or code search) but not a tool for making a living.
66 posts | 1 followersFollow
Alibaba F(x) Team - June 20, 2022
Alibaba F(x) Team - February 21, 2022
Alibaba Clouder - December 31, 2020
Alibaba Cloud MaxCompute - February 28, 2020
Alibaba Clouder - April 1, 2021
Alibaba Clouder - November 25, 2020
66 posts | 1 followersFollow
A low-code development platform to make work easierLearn More
More Posts by Alibaba F(x) Team