GitHub Copilot is a tool that helps developers write code faster and more efficiently by providing suggestions and even entire blocks of code based on comments, variable names, function names, and more.
GitHub Copilot saves time when writing standard code structures and algorithms. It is helpful for beginners just learning to develop in a new language and for experienced developers who want to avoid manually writing repetitive functions and structures.
GitHub Copilot can be integrated into various development environments, including:
It also supports a wide range of programming languages, such as:
GitHub Copilot is compatible with popular frameworks and libraries like React, AngularJS, VueJS, Spring, Django, Ruby on Rails, and more.
In this tutorial, we’ll explain how to use GitHub Copilot when developing in Python and how it can help improve coding efficiency.
GitHub Copilot is currently available as a subscription service for $10 monthly.
GitHub Copilot provides suggestions and autocomplete features based on user comments written in natural language and existing code. To achieve this, GitHub trained Copilot using publicly available repositories hosted on its platform.
The effectiveness of Copilot depends on the availability of public repositories in a given programming language. It works well with popular languages like Python and offers reliable suggestions. However, for less common languages, its performance may be weaker, providing fewer and less accurate recommendations.
PyCharm, a JetBrains IDE, supports GitHub Copilot. To integrate it into your project, follow these steps:
Now, you can install the GitHub Copilot plugin in PyCharm:
Now, GitHub Copilot is fully integrated into your PyCharm project.
Let's write a simple function to verify that we have successfully installed the GitHub Copilot plugin.
For example, start typing a function to add two numbers, like:
def add(a, b):
As you begin typing, Copilot will suggest completing the function:
Action |
Windows |
Mac |
Activate inline suggestions |
Alt+\ |
Option+\ |
View next suggestion |
Alt+] |
Option+] |
View previous suggestion |
Alt+[ |
Option+[ |
Accept suggestion |
Tab |
Tab |
Reject suggestion |
Esc |
Esc |
Open all suggestions in a new window |
Ctrl+Enter |
Ctrl+Enter |
GitHub Copilot doesn’t just rely on function names—it also generates code based on comments.
For example, if you write a function for matrix multiplication with a descriptive comment:
def multiply_matrices(A, B):
# Multiply matrix A and B and return the result
Copilot may suggest the following:
def multiply_matrices(A, B):
# Multiply matrix A and B and return the result
rows1 = len(A)
cols1 = len(A[0])
rows2 = len(B)
cols2 = len(B[0])
if cols1 != rows2:
raise ValueError("The number of columns in the first matrix must be equal to the number of rows in the second matrix")
result = [[0 for j in range(cols2)] for i in range(rows1)]
for i in range(rows1):
for j in range(cols2):
for k in range(cols1):
result[i][j] += A[i][k] * B[k][j]
return result
To verify that this function works correctly, let’s use the NumPy library:
import numpy as np
matrix1 = [[15,24],[12,44]]
matrix2 = [[112, 22],[55,90]]
m1 = np.array([[15,24],[12,44]])
m2 = np.array([[112, 22],[55,90]])
print(multiply_matrices(matrix1, matrix2),'\n')
print(np.dot(m1, m2))
Output:
[[3000, 2490], [3764, 4224]]
[[3000 2490]
[3764 4224]]
As you can see, the function Copilot correctly performs matrix multiplication.
GitHub Copilot is a very useful tool, but it has some drawbacks.
The code suggested by Copilot may contain errors. It does not perform self-checks, meaning developers must test the generated code themselves. Additionally, Copilot doesn’t always produce optimized code, both in terms of efficiency and structure. In summary, all Copilot-generated code must be reviewed and tested.
Modern Integrated Development Environments (IDEs) do more than just provide a space for writing and debugging code—they also offer built-in suggestions. For example, when using a built-in function in PyCharm, the IDE provides information about its attributes. At the same time, Copilot might suggest something different, which can be confusing for the developer.
This is a controversial aspect of using Copilot in commercial development. Since Copilot was trained on public repositories, it could theoretically suggest licensed code. This raises concerns about intellectual property rights when using Copilot-generated code in proprietary projects.
Copilot doesn’t teach developers how to write code—it writes it for them. For junior developers, it’s important to gain hands-on experience by implementing common functions and algorithms manually. Over-reliance on Copilot might slow down skill development.
GitHub Copilot is a useful tool for handling repetitive coding tasks. According to GitHub’s own research:
Copilot should be seen as an assistant—someone you can delegate tasks to while focusing on more important and complex problems. However, developers must carefully review all code generated by Copilot to ensure quality and correctness.