Getting started with AI assisted development - GitHub Copilot

Developer
AI development

Generated with Clipdrop by stability.ai

In June 2021, Copilot was launched by Github, the innovative tool which is to help developers while coding, thus to save time and enhance coding productivity.  Copilot utilizes the potential of Codex, an OpenAI generative pre-trained language model. 

In this article we'll go over everything you need to know about Copilot; setting up, how to use it to improve the development process, and some tips & tricks to make the most of Copilot and share some examples for JavaScript and PHP.

Copilot works by using real-time code analysis and generating context-based recommendations from millions of code lines it had been pre-trained with. It may suggest function calls, auto-complete code snippets and even write entire programs for you. It is like having a developer friend (yes, just like a copilot) to ask for help at your disposal all the time. Copilot is able to do this by getting the context from comments and code and instantly suggest lines of code or even whole functions. 

As a result, it is extremely accurate and powerful since it can comprehend the context and syntax of different programming languages. It's also worthy to note that it's not flawless so there is the need to vet the suggested code. Nonetheless it's a good place to begin because it is difficult at times to recall syntax, look up APIs and function names.

Saving time and minimizing errors are two of Copilot's key advantages for developers. Developers can concentrate on solving challenging problems rather than writing repetitive code by following Copilot's recommendations. This may result in shorter development cycles and higher-quality code. 

Copilot isn't the only extension of the OpenAI model, there are others like CodeGPT, ChatGPT, Tabnine. These are all AI assistive tools that can help while you code.

Setting up Copilot

Most of the developers in Ramsalt Lab use PHPStorm as code editor, so that’s what we will use as an example when setting up Copilot. It should be fairly similar in other code editors.  

Under the File menu for Windows or under the name of your IDE for Mac, click on Settings for Windows or Preferences for Mac.

  • In the left-side menu of the Settings/Preferences dialog box, click Plugins.
  • At the top of the Settings/Preferences dialog box, click Marketplace. In the search bar, search for GitHub Copilot, then click Install.
  • After GitHub Copilot is installed, click Restart PHPStorm.
  • After PHPStorm has restarted, click the Tools menu. Click GitHub Copilot, then click Login to GitHub.
  • In the "Sign in to GitHub" dialog box, to copy the device code and open the device activation window, click Copy and Open.
  • A device activation window will open in your browser. Paste the code, then click Continue.
  • GitHub will request the necessary permissions for GitHub Copilot. To approve these permissions, click Authorize GitHub Copilot Plugin.
  • After the permissions have been approved, your  IDE will show a confirmation. To begin using GitHub Copilot, click OK.

A little side note here GitHub Copilot is free to try for 60 days. After you get to choose whether to continue with the product at $10 monthly or $100 annually. But there are cases where you can use the product for free, if you are a verified student, teacher, and or person who maintains some popular open-source product(s).

To disable Copilot from assisting you click the status icon in the lower panel of the PHPStorm window, it turns gray to mean it's disabled and on clicking again is highlighted meaning it's enabled.

Test out Copilot for the first time

Viola, you are ready to go, let’s try it out.

  • first create a new .js file
  • Start with a comment write a javascript function to calculate the mean and hit Enter

You would notice Copilot gives a suggestion on the function hit Tab to accept.

Let us do the same using PHP, we repeat the file creation but this time it will be a .php file.

Tips & Tricks

As mentioned, Copilot is pre-trained and as such some tricks make it work effectively.

  • Be mindful of the development environment, while Copilot offers suggestions for several languages and a variety of frameworks, we suggest you use Copilot with JavaScript, Python, Ruby, C#, PHP and TypeScript, as it works the most efficiently with these.
  • Mind your context, remember that Copilot is AI driven and the more context you provide the better and more accurate its suggestion would be for you.
  • Although Copilot walks with you while coding, be mindful of the pitfalls and always remember to test the code.

Copilot is able to access the context of your code and bring forth some ideas and code fragments that can help speed up the development process.

Due to its wide reach on programming languages and frameworks, it has the potential to grow into a vital tool for developers of all levels on the development ladder.

Copilot is still in its early stages and shouldn’t be used as a replacement for good coding standards and good programming practices, but it will certainly help you on the way.

Latest news

20 employees from Ramsalt Lab had the opportunity to attend DrupalCon in the city of Barcelona. Read our top recommendations from the conference! 

Photo of Hansa Pandit
Hansa Pandit

Vi søker en visjonær og handlekraftig daglig leder som kan ta vårt utviklingsfirma til nye høyder! Er du en strategisk leder med solid forretningsforståelse og en sterk lidenskap for teknologi og innovasjon? Da vil vi høre fra deg!

Yngve W. Bergheim
Yngve W. Bergheim

The European AI Act came into force on 1 August 2024, bringing new rules and regulations for artificial intelligence within the EU. If you use AI on your website or for content-creation it is important to understand how these changes could have an impact. 

Nina
Nina Holzapfel

We have gathered some reasons why Drupal could be a better choice for your needs.
 

Yngve W. Bergheim
Yngve W. Bergheim