Everybody is talking about GitHub Copilot, and I’m sure you’ve heard all about it too. What we have in our hands is a revolutionary tool for assisting programmers to write code more efficiently with better quality. From this, I can confidently say that AI-assisted programming is here to stay. For anyone not in the loop, GitHub Copilot is an AI pair programmer that uses machine learning to suggest code snippets and complete lines of code directly from your favorite IDE.

In this blog, we’ll discuss Copilot from a Java developer's point of view and explain how the practices and principles listed below may also apply to other languages.

Copilot or ChatGPT?

In the world of artificial intelligence, we have a couple of tools that can help you with your work: ChatGPT and GitHub Copilot.

ChatGPT is an AI language model that generates human-like language and performs natural language processing tasks, such as translation and summarization. ChatGPT can produce human-like responses to different queries and has been trained on a diverse range of text data, like news articles, books, and web pages.

On the other hand, Copilot is an AI-powered coding assistant trained on a large amount of code data and can adapt to a developer's coding style and preferences over time. It works by analyzing the code you've already written and the context of your current coding session to suggest code snippets and auto-complete code for you. Additionally, Copilot can offer documentation and examples to help programmers to write better code.

Copilot is built on top of OpenAI's GPT-3 natural language processing model, which means it can understand natural language commands and generate code in response to them. It supports several programming languages, including Java, Python, JavaScript, TypeScript, Ruby, Go, and Rust.

It writes code with you

Code compilation enables faster coding by suggesting longer snippets and method names based on other content, like repository class suggestions based on domain classes. Code conventions are maintained when working with more extended snippets and method naming. Code compilation can be handy when writing code required for most projects (like repository handling). It allows for a quick generation of basic structures while enabling coders to emphasize the problem they’re resolving instead of writing lengthy implementations.

Focusing on the things that matter

The most significant boost to productivity that Copilot offers is that it enables developers to focus on challenges rather than repeatedly writing the same code again and again. For example, the first >100 lines are always the same in building microservices, and it feels like a monkey could do it. But it needs to be written differently every time due to the data model and other specific project details, usually in a project with several microservices to be built. With Copilot, this can be easily auto-generated, and a developer can focus on the specific analytical challenges and creative problem-solving instead of writing a tedious boilerplate - which you can’t copy-paste into place.

Having best practices in place

When developing a product on a larger scale, there can be some variation between coding conventions that vary from developer to developer (or at least there might be small mistakes in the conventions like indentations, white space, etc.). With Java, there are widely spread and generally accepted conventions, like writing classes that start with uppercase letters and methods and method names with lowercase, e.g., class Car  and method getTires().

Copilot makes code conventions much easier to maintain, providing better code quality for the whole team. It also helps to write more testable code because it’s taught using best practice models. Additionally, Copilot makes code reviews easier because code conventions are already followed, and reviews can focus on functionality, not convention.

It doesn't require using best practices, but because it is taught using them, suggestions are provided with best practices.

builder

template

You need to understand what you are doing

Have you written tens and tens of methods and realized you don’t have any unit tests in place? Again, writing tests for each method separately is tedious and not the most enjoyable task. Though in this case, you need to know what you are doing. You might write code in a highly regulated environment, such as banking or medical when using Java. So having tests in place is one thing, but having meaningful tests is a different ordeal. As with regulated projects, someone must always run tests like this correctly.

With Copilot’s help, you can easily autofill the boilerplate of the test cases for all the methods in place. But you still need to focus on what it is you are testing. Copilot makes testing more accessible, but it doesn’t think for you. That's why you need to know what you're doing to write meaningful and working tests. For example, in some cases, we’ve encountered division-by-zero errors with auto-generated tests. 

TL;DR: GitHub Copilot is a great assistant

GitHub Copilot marks the beginning of a new era for developers! Unlike previous IDEs that rely on basic auto-completion of method names based on documentation, this AI-assisted tool is a significant leap forward. It and other similar tools are revolutionizing how coders work, so if you're curious whether you should give it a go, the answer is yes.

Published: Aug 2, 2023

Updated: Jan 30, 2024

Software developmentCI/CD