Air plane pilots

Coding with GitHub Copilot

Exploring Its Pros and Pitfalls from Side Projects to Real-World Applications

GitHub Copilot is an AI-powered code completion and generation tool that works seamlessly within integrated development environments (IDEs). It has revolutionized the industry, capturing the attention of the software development community since its release and has the potential to significantly impact the way developers write code, making the coding process more efficient and collaborative.

However, Copilot also raises important questions and challenges like code quality, security, and overreliance on AI-generated code are topics that need to be addressed. Developers must strike a balance between leveraging Copilot’s capabilities and maintaining a deep understanding of the code they write.

Over the past month, I’ve extensively utilized Copilot in various scenarios: from small-scale personal projects and contributions to open-source initiatives to using it daily on the e-commerce platform where I work.

The technologies employed in these projects include Ruby on Rails, React, and Vanilla JavaScript.

With that in mind, let’s explore the advantages and disadvantages of GitHub Copilot more thoroughly.

Copilot in Side Projects

Copilot speeds up coding, but blindly following its suggestions isn’t the way. I use its assistance selectively, guiding my workflow by choosing which suggestions to incorporate.

Use case

Here’s an example showcasing Copilot’s usage on my personal finance manager toy project:

The project contains a few basic concepts such as users, which have many budgets, and budgets that have many expenses.

On the budget’s controller, I created a new method invite which would be an endpoint to a user invite another, here’s the code suggested by Copilot:

def invite
    @budget = current_user.budgets.find(params[:budget_id])
    @user = User.find_by(email: params[:email])

    if @user.nil?
        render json: { error: "user not found"}
    elsif @budget.users.include?(@users)
        render json: { error: 'user is already on budget' }
    else
        @budget.users << @user
        render :show, status: :created
    end
end

When taking a look at the provided code, it seems to align with the existing project models.

However, what it doesn’t account for is the complexity that comes from inviting another user to join a budget. This could involve the creation of an Invitation model, incorporating fields for the sender, receiver, associated budget, and status indicator, among other requirements, such as:

  • When a user initiates an invitation, it could generate a new Invitation record, initially marked as "pending."
  • From there, the invited user has the option to either accept or decline the invitation.
    • If accepted, the status transitions to "accepted," granting the invited user access to the shared budget.
    • if declined, the status shifts to "declined", and the system should notify the users about each step.

This short scenario exemplifies a situation where GitHub Copilot can assist in generating basic code structures. However, it becomes evident that the complexity of user interactions, in this case, requires a deeper understanding of the application’s logic.

While Copilot can lay the foundation, the nuances of specific domain knowledge demand the expertise of the developer, this underscores the importance of human insight in ensuring the best implementation.

Copilot in real-world apps

I work with a team on an E-commerce platform that has several repositories and has been around for over 8 years. My experience using Copilot on this app and open-source projects was more limited.

When coding something that depends on the project’s concepts, it hallucinates and suggests some incorrect code more frequently due to the complexities of the projects. It all contributes to the limitation of Copilot, the problem is that it’ll always suggest code, doesn’t matter if it’s hallucinating.

However, in more specific concepts, when the knowledge it needs to achieve something is mostly language syntax or pure logic, it performs better, so short suggestions are more accurate.

Pros of Using GitHub Copilot

Before giving my thoughts, let’s take a look at the research conducted by GitHub Next in September 2022 about the GitHub Copilot’s impact on developer productivity and happiness

Github Research on Copilot’s Impact

GitHub came up with 2 experiments:

First experiment

Through a large-scale survey, they wanted to see if developers using GitHub Copilot see benefits in other areas beyond speeding up tasks. Here’s what stood out:

  • Improving developer satisfaction. Between 60–75% of users reported they feel more fulfilled with their job, feel less frustrated when coding, and can focus on more satisfying work when using GitHub Copilot.
  • Conserving mental energy. Developers reported that GitHub Copilot helped them stay in the flow (73%) and preserve mental effort during repetitive tasks (87%).

Second experiment

They recruited 95 professional developers, split them randomly into two groups, and timed how long it took them to finish a task. One group used GitHub Copilot to complete the task, and the other one didn’t.

In the experiment, they measured—on average—how successful each group was in completing the task and how long each group took to finish.

  • The group that used GitHub Copilot had a higher rate of completing the task (78%, compared to 70% in the group without Copilot).
  • The difference was that developers who used GitHub Copilot completed the task significantly faster–55% faster than the developers who didn’t use GitHub Copilot.
  • Specifically, the developers using GitHub Copilot took an average of 1 hour and 11 minutes to complete the task, while the developers who didn’t use GitHub Copilot took an average of 2 hours and 41 minutes.

My Experience

In my view, it significantly speeds up the development process by offering smarter code completion compared to traditional IDEs, eliminating the need for constant browser switches to search for small solutions or specific language syntax, saving time.

Moreover, it enhanced my development experience by offering collaborative problem-solving. While I have my ideas, Copilot presents its approaches and allows me to choose the best solution or combine different ideas for better results.

Experienced developers stand to gain significantly from GitHub Copilot, leveraging their broader knowledge of the complexities of software development to navigate the pitfalls that novice developers might encounter while using it blindly.

Cons of GitHub Copilot

While GitHub Copilot offers convenience and assistance in generating code snippets, it has limitations that should be considered before relying solely on it for development.

Limitations

One of the key limitations of GitHub Copilot is the potential for errors in the generated code. Even though it can give you suggestions and code snippets based on existing code, it might not always come up with precise or ideal solutions. The grasp it has on the context and demands of complex projects is limited and it may not capture some nuances and specific needs, which could result in potential bugs or inefficiencies in the generated code.

Flow interruptions

Another aspect that bothered me was the interruptions in flow caused by Copilot being too noisy.

For example, when you’re contemplating an approach to solve a problem, a suggestion suddenly appears in your IDE. Your focus shifts to that suggestion, causing you to lose your initial concentration.

Also, having to review code suggestions from GitHub Copilot could disrupt the flow while working on projects.

Not recommended to total beginners

I wouldn’t recommend it for someone completely new to the development world, and there are a few reasons for this:

  • May disrupt the learning process. In programming, we learn through practice, and GitHub Copilot might shortcut some essential processes and paths crucial for the learning experience.
  • You have to be cautious about it. There are instances where it generates code with partial errors, and since it doesn’t test your code, it can be vulnerable or buggy.

Maximizing the Benefits of GitHub Copilot

To make the most out of GitHub Copilot and avoid most challenges, it’s a good idea to keep some helpful tips in mind.

  • Remember that GitHub Copilot is designed to aid developers, not replace them. While it can generate code suggestions, human judgment, and expertise are still necessary for quality control. You need to guide the tool, not be guided by it.
  • When using GitHub Copilot, developers should actively review and validate the suggestions provided, by closely reviewing the generated code for accuracy, efficiency, and compliance with the project’s coding standards.
  • It is important not to blindly accept all suggestions without proper inspection, don’t trust by default. Read the suggestions and be sure they make sense.
  • When providing comments for the code you want GitHub Copilot to generate, aim to be highly specific. Avoid instructing it to generate large blocks of code, as it may lose its focus and accuracy along the way.

Concluding

The power of GitHub Copilot can be harnessed to enhance coding productivity greatly, but it’s crucial to use this tool wisely and with caution. It has the potential to streamline coding processes by providing intelligent code suggestions and automating repetitive tasks. By leveraging its capabilities effectively, developers can save time and effort in writing code.

An important thing to remember that GitHub Copilot is an AI-powered tool and not a substitute for human expertise. Use it as a helpful assistant rather than blindly relying on its suggestions.

To maximize GitHub Copilot’s power, developers should critically evaluate its suggestions and ensure that the generated code aligns with best practices and project requirements. Regular code reviews and manual testing are still essential for maintaining code quality.

I recommend you give GitHub Copilot a try, some of my experienced friends have used it and loved it, while others didn’t find it suitable for their needs.

Ultimately, the best way to determine if it’s the right tool for you is to experiment with it yourself.

We want to work with you. Check out our "What We Do" section!