Software development is changing as a result of GitHub Copilot and other AI pair programming tools. You can create code more quickly and with less effort with the aid of GitHub Copilot, an AI pair programmer. We suggest that you, the developer, are necessary for this tool to function by using the terms "AI pair programmer" and "Copilot"! It isn't magic. Despite occasionally feeling as though it could, it cannot read minds. However, GitHub Copilot improved my productivity and self-assurance as a programmer by providing code completion suggestions based on the context of my project and style guidelines.
The best part is you can use GitHub Copilot to increase your velocity and confidence as you code, too! In June 2022, we made GitHub Copilot available to all individual developers. You can learn how to get started with GitHub Copilot here.
If it’s not reading minds and it’s not magic, then how does it work?
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 favorite applications, like Duolingo, use GPT-3 for grammar correction.
For more information on how GitHub Copilot works and its effectiveness, check out the following resources:
- GitHub Copilot Research Recitation
- How GitHub Copilot helps improve developer productivity
- Research: quantifying GitHub Copilot’s impact on developer productivity and happiness
Unexpected yet valuable GitHub Copilot use cases
When the extension is installed, it will start to propose code as you type. How can you use the GitHub Copilot plugin to its fullest potential?
In order to assist your AI pair programmer in producing the desired solutions, I first advise writing clear, understandable comments. However, if you're curious about other ways to use GitHub Copilot that you might not have considered, we've put together a list of amusing and useful use cases that we've observed in speaking with developers. I hope the examples below motivate you!
1. Assisting non-native English speakers
Beyond English, GitHub Copilot can comprehend other languages! This is advantageous because programming languages are based on American English, which is useful for developers from diverse backgrounds. For example, the CSS property color
is based on American English, so it is unfamiliar for native British-English or Canadian-English speakers who use the spelling ‘colour’. Forgetting the correct spelling and syntax can often result in typos, unexpected errors, and lost time.
In the GIF below, I wrote a comment in Spanish that says, “importar,” which translates to “import.” GitHub Copilot quickly completed my comment in Spanish and imported the necessary libraries as the comment described.
2. Creating dictionaries with lookup data
Martin Woodward, Vice President of Developer Relations at GitHub, shared this tip with us! GitHub Copilot is great at creating dictionaries of lookup data. Create a dictionary of two-letter ISO country codes and the contributing country names in GitHub Copilot by directing it in a remark. The first few lines of code and a note should assist GitHub Copilot in producing the desired outcomes. For an example in visual form, see the GIF below!
3. Testing your code
A crucial, if occasionally tiresome, stage in the software development lifecycle is writing tests. Writing unit tests, visual regression tests, and other types of tests can all be done more quickly using GitHub Copilot because it is so good at pattern recognition and pattern completion.
Check out these resources to learn more about using GitHub Copilot for testing:
- Using GitHub Copilot to Automate Tests – An Applitools blog post by GitHub Star, Colby Fayock
- Make Testing Easy with GitHub – An Applitools webinar by me
- Writing Better Tests with AI and GitHub Copilot – A CodeCov blog post
4. Matching patterns with regular expressions
By using GitHub Copilot, you can match character combinations in strings without having to waste time playing around in a Regex playground or searching StackOverflow. Instead, you can use GitHub Copilot's suggestions by writing a remark or the name of a function.
I used Copilot to help me validate a phone number!
GitHub Copilot can help you remove white space from a string!
5. Preparing for technical interviews
Although it may seem out of the ordinary, developers like myself use GitHub Copilot to prepare for interviews.
Here’s the strategy:
- First, I try to solve the problem without GitHub Copilot.
- If I’m feeling extremely stuck and disheartened while solving the problem, I’ll activate GitHub Copilot and use it to generate ideas on how to solve the problem better.
- Subsequently, I’ll delete the code GitHub Copilot generated, deactivate GitHub Copilot, and make another attempt at finding a solution with the new information in mind.
I resist the urge to give up when I use this strategy. Even without a mentor or peer to provide me with advice, I continue to learn new views rather than giving up. Copilot on GitHub becomes my online mentor. But, note, that I highly discourage activating GitHub Copilot during an interview (that’s cheating!).
Interestingly, chess players take a similar approach when preparing for matches. It’s common for chess players to practice against AI engines to advance their skills. In the publication, Towards Data Science, Bharath K writes, “Artificial Intelligence has influenced the way in which chess games are played at the top level. Most of the Grandmasters and Super Grandmasters (rated at a FIDE above 2700) utilize these modern AI chess engines to analyze their games and the games of their competitors.” Learn more about the influence of AI chess engines here.
If AI is improving chess players' abilities, maybe it may improve developers' problem-solving abilities by forcing them to approach problems in alternative ways.
You can learn more about leveraging GitHub Copilot to solve algorithmic problems here. In the example below, I wrote a comment that says, “write a binary search algorithm,” and the first line of my function. GitHub Copilot correctly completed the function.
6. Sending tweets
Of course, you could just send a Tweet using the Twitter app, but using your IDE to do it is more entertaining! Making demonstrations is a component of my duties as a Developer Advocate. In a recent livestream, I had to demonstrate using Twitter API v2 with GitHub Copilot in Python, a language that I rarely use. GitHub Copilot saved the day and generated the code I needed after I wrote a few comments. Read my DEV post if you want to try sending a tweet with GitHub Copilot, too!
7. Exiting Vim
Vim newbie developers frequently inquire how to leave the editor. Vim exit issues are so frequent that they have their own internet meme! You can quit NeoVim using GitHub Copilot because it is integrated with Visual Studio Code, JetBrains, and Neovim, a forked version of Vim with extra capabilities. In the video below, Brian Douglas uses GitHub Copilot to exit NeoVim, by writing a comment that says, “How do I exit vim?”
8. Navigating a new codebase with Copilot Labs
GitHub Copilot Labs is a complementary extension that comes with GitHub Copilot access. The GitHub Next team developed GitHub Copilot Labs, an experimental sidebar, to help developers translate code from one programming language to another and get a step-by-step explanation of code snippets.
There’s no easy method for building a mental model of a new codebase, but these two features within GitHub Copilot Labs can help. By translating code snippets to languages they’re more familiar with and using the ‘Explain’ feature to gain an understanding of the code, developers can better comprehend complex blocks of code.
Wrap-up
As you can see from the examples above, GitHub Copilot can increase your daily productivity in a variety of ways (many of which we're still learning about! ), and I would like to kindly remind you that since GitHub Copilot is an AI pair programmer, you should review the generated code before pushing it to production just as you would with your coworkers' or even your own! GitHub Copilot is a powerful tool, but sometimes it can be inaccurate or use an old version of an API.
Nevertheless, the team at GitHub continues to work hard and learn from our users to develop a better experience and generate better results with GitHub Copilot. I’m excited to witness and experience the evolution of AI pair programming tools. If you’re just as eager as me, sign up for GitHub Copilot today!
Social Plugin