By Ali Yun-Qin Qi
GitHub Copilot has attracted a lot of attention since its launch. Its amazing ability to recommend code has been hard to find, and some other issues have been raised, such as whether programmers have lost their jobs since then. And the “copyright” of its recommended code. However, this article does not intend to discuss the above problems, just some practices for Copilot code recommendation ability after my trial application is approved, I hope to help you.
Ability to collect
Here I’ve broken down GitHub Copilot’s capabilities into three broad categories: auxiliary programming, text-to-code, and empirical inference.
Auxiliary programming
As the name implies, auxiliary programming is to predict and recommend possible code based on the context of user input during the programming process, so as to make programming more efficient. First, the most common React component is written and compared:
-
Basically, you can recommend the code for the React component that works without any context.
-
With IProps declared, the recommended component code contains the interface definition
-
Code recommendations for introducing Dialog and Table components
To summarize: it’s possible to recommend usable code without context, even if it’s probably not what we want; When context is present, the code recommended by context is more accurate, and the richer the context, the more accurate the recommendation.
Text to code
Text-to-code is the automatic generation of object code from a description. Here are a few examples:
-
String inversion
-
Let’s do something a little harder. Browser check
As you can see, it took a while, but the code was recommended and it looks like it’s going to work, but whether it’s going to work or not has yet to be verified. (PS / * @ cc_on! @*/ Also really ie11 following unique code, can refer to here)
- Here’s another common interview question: quicksort
Conclusion: Some commonly used functions and algorithms can be generated according to the description of the code, but the accuracy of the generated code can not be guaranteed, the code is most likely from the actual code snippet, it is up to the developer to judge whether it is correct or not. I suggest that the generated code is for reference only and should not be used directly in production.
Experience concludes
Copilot can automatically find patterns hidden in the code. In addition, with more use, it can learn personal coding habits and recommend personalized code. Here’s an example:
Let’s do a more complicated one,
This capability is quite impressive, and I guess the logic behind it is similar to Code2Vec, recommended based on the similarity of text semantics.
Personal advice
Copilot works as a code aid, but there are a few things to be aware of:
-
⚠️ Do not rely too much on generated code, as accuracy cannot be guaranteed.
-
⚠️ does not have a native version of Copilot yet, but you need to be connected to the Internet to use it, so be aware of code security issues.
-
⚠️ think of it as a development aid (code completion, code search) rather than something to eat.
Tao department front – F-X-team opened a weibo! (Visible after microblog recording)In addition to the article there is more team content to unlock 🔓