Desarrollo de Software con GitHub

How to use GitHub Copilot and enhance Software Development

The next era in software development has arrived, and it’s called GitHub Copilot. A tool that you can purchase and install in less than 10 minutes in your favourite code editor or IDE. It’s the perfect blend of the power of artificial intelligence and machine learning in the writing process.

In this article, we will explore how to make the most of GitHub Copilot and boost your efficiency in software development.

Before starting with GitHub Copilot

In this case, we will focus on using GitHub Copilot in Visual Studio Code. To do this, we must first install it; you can get it from here. Once installed, access the Extensions Marketplace and search for the one you’re interested in, as illustrated in the following image:

¿cómo instalar GitHub?

Once found, just click the install button, and you’ll have everything set up. It is recommended to restart the application after installation.

After this, we need to make sure the extension is correctly activated. In the bottom right corner of the Visual Studio Code window, you will see the GitHub Copilot icon. If you click on it, you may encounter the following error:

ejemplo con GitHub Copilot para ilustrar un prompt

After clicking the button, a window will open in the browser to log in to your GitHub account. For this to work, the GitHub account must have a paid subscription to the GitHub Copilot service. You can get payment-related information from the official page.

After authorizing the use of the GitHub account in external applications, everything will be set up. From here, we just need to get to work.

A tool almost made to measure for GitHub Copilot

From the settings section (*File > Preferences > Settings*), we can access the extension settings. For example, we could edit a keyboard shortcut to enable or disable Copilot, modify the number of suggestions it offers, or change the languages in which it can be used.

ejemplo con GitHub Copilot para ilustrar un prompt
ejemplo con GitHub Copilot para ilustrar un prompt

As we correct the text suggested by Copilot, it will learn from the code we are introducing into different files and improve future suggestions. The more we interact with the tool, the more precise and adapted the code generation will be.

If we work in a team where everyone uses GitHub Copilot, it would be interesting to establish common guidelines for the use of the tool to maintain some consistency in the team’s coding style.

Customizing preferences and training GitHub Copilot is essential to take full advantage of its capabilities and tailor it to our development style. This will significantly increase the quality of our code.

What are the limitations of GitHub Copilot?

Despite being a revolutionary tool, it is not without limitations and challenges that we must take into account. Although GitHub Copilot is powerful, it does not always generate 100% accurate code. It may make mistakes or produce unreliable solutions. The developer needs to review and validate the generated code to avoid issues. It is a tool in the hands of the developer, not a substitute.

Since it feeds on the code uploaded to GitHub Copilot servers, we must be careful when using the tool. Especially if we are dealing with sensitive or confidential information in project files.

The tool depends on the programming language and the concept of the project, so there may be cases where certain languages or domains may be more challenging for the tool.

consultoría programando con GitHub teniendo en cuenta las limitaciones de la herramienta

How to start using GitHub?

Short answer: within a comment, enter what you want the tool to generate.

ejemplo con GitHub Copilot para ilustrar un prompt

Long answer: GitHub Copilot, like other AI tools of the moment, cannot automatically infer what we need. In other words, the more information and context we provide about what we are looking for, the more accurate its response will be. Following the previous example, if we want the application to provide something specific, we must explicitly request it.

With this example, we have managed to generate a natural language interface without worrying about the type of nomenclature to use.

Can it also generate methods with more or less logic? Of course, as long as we provide specific guidance in the method header to inform it about what we want. A simple example would be the following:

ejemplo con GitHub Copilot para ilustrar un prompt

We can also add an additional level of complexity:

ejemplo con GitHub Copilot para ilustrar un prompt

This example is perfect for illustrating that this tool may not take into account all aspects of our prompt. With a compound name, such as “Juan Alberto,” if the user writes it in lowercase, the tool would return the name as “Juan Alberto.” To avoid this, we could add a simple reminder in the code in the form of a comment:

A good way to train the tool is to remove the proposal that doesn’t fit and recreate it until you find a satisfactory solution. Another way to train GitHub is to write part of the code and allow the tool to complete it. So that it gets “used to” our software development style.

How to improve prompts in GitHub Copilot?

The prompt is the most important part when using any AI, even more than the tool itself. It holds the responsibility of obtaining accurate and useful results. Some tips that can be used include:

1. No ambiguities

GitHub Copilot is an AI, not our coworker, so it needs you to tell it exactly what you need; therefore, you must be as specific as possible. For example, instead of “Generate a bar chart for an object,” you can enter “Generate a bar chart for the chartData object, ordering items from lowest to highest based on the value of the measure variable.”

2. An example is worth a thousand words

Including an example of the context you are addressing can help the AI better understand what you are expecting. In case the generated code is not what is expected, you can add a comment that says, “This is not what I need. Please generate the code following these instructions,” along with a list of things you need. Following the previous example, we can add the prompt: “Generate the bar chart using this dataset as an example, which has the same structure as the input: [example of data using a JSON].”

3. Try, Redo, and Redo

We have already seen that it is an imperfect tool. If we don’t like what the AI generates, we can refine the AI’s output by providing precise feedback. For example, if we are not convinced by the generated bar chart, we can request it to be generated in a specific library, by entering a new comment that says, “I need you to generate the bar chart using the Kendo library.”

The community is a great source of knowledge

There are active communities of AI tool users, such as the r/OpenAI from Reddit, where there are always other developers sharing their tips on how they make their prompts and how they have improved them. Participate in user forums, open-source project development groups, and social networks like LinkedIn to share and learn new prompt engineering strategies.

Throughout the article, we have seen that GitHub Copilot is more than just a code assistant. It is a development companion that understands you, suggests solutions, and saves you time. With GitHub Copilot, you can create amazing applications with less effort. Want to know more about this revolutionary technology? We invite you to read our article “GitHub Copilot: Improve development speed“, where we explain how it works, its advantages, and how you can start using it today.

Don’t miss the opportunity to enhance your productivity and creativity with GitHub Copilot. Contact us now and discover everything we can do for you!

Elio San Martín Gallart – Software developer at Itequia