Github Copilot

Github Copilot

13 - 06 - 2024
10 min


Do you like polls, questionnaires? Take our internal questionnaire:

  • Did you know that according to IBM research, the average developer writes 12 lines of code per day? Do you think you will write more? – 1 point
  • Do the bellies of your fingers hurt from constantly "typing into the keyboard"? – 2 points
  • Are You tired of writing repetitive code all the time, such as unit tests, but want to deliver it? – 2 points
  • Sometimes you come across a simple task that everyone has already written, but not you, and your head hurts just thinking about it? – 2 points
  • Are you new to the project and slowly absorbing coding-style? – 1 point

If you have at least 3 points from the questionnaire - try the unique, wonderful and sometimes even magical Github Copilot (or another AI assistant - for example, the one from Czech-based Jetbrains, which I will describe here). There will definitely be areas where it could help you.

Copilot/Jetbrains AI Assistant is a generative artificial intelligence - similar to the well-known Chat GPT - but differs in training data. Chat GPT is general trained on Reddit discussions, for example, Copilot is trained on code stored in Github - and there are loads of it there.

Code completion

Copilot, integrated into your IDE, is not the silver bullet of software development, it is not Sherlock Holmes to solve your every puzzle - it is more Dr. Watson, who always pushes you forward a little when you don't know where to go anymore or you just don't want to think.

Here it will supply a few characters, but sometimes it will show up and code the whole method for you - here is an example of a method for generating a PNG image for unit test purposes.

Intelisense on steroids, one would say, right? :) But it definitely doesn't end there, Copilot understands text in a way and you can chat with it in your favorite IDE. For example, you wrote a new feature and you want to test it… but who likes to write unit tests, right?

Write unit tests

Who likes to write them, right? But you can't do much without them - so a helper would be useful ;) A simple dialog where you choose a test framework, check that you want to use AI

…and voilá

As with other cases where you use AI to generate code, it should always be checked to make sure it works.

Explain code

We see the greatest benefits of AI for beginner programmers – more senior developers usually have no problem understanding existing code, but for a junior, the option to have a selected part of the code explained (Explain Code) is very useful.

Shy programmers (which is the majority ;) often have trouble asking more experienced colleagues what the code actually does, or spend too much time trying to understand it without help. That way AI can help them - without stressful interaction with other people ;)

Of course, Copilot is not for free, but it costs a few minutes of a junior programmer's work per month - adding such an "explainer" to the team is not an expensive matter at all.

Suggest refactoring

We're walking on thin ice here and getting into AI features that can be bad to your codebase in the wrong hands.

An AI assistant can suggest refactoring of a given part of the code - it should be remembered that AI assistants use statistical language models. Simply, using mathematics, it tries to "guess" what next word (or token) to generate to the output. This means that the generated code can usually be compiled, but its correctness is not guaranteed due to the nature of the AI ​​assistant function. Taking "assistant" code and replacing the original should then be considered and treated like any other (manual) change. And if you have well-working unit tests, with which you can verify that the code works even after refactoring - that's only good ;)

Write Documentation

For me, one of the more questionable features of AI assistants. The code should be readable and understandable - self-descriptive, as well as the signature of it‘s functions. If you want, you can have the documentation generated by the assistant. The problem is that it tries to please you and generates really rich documentation, often only expanding the names of methods and their parameters ;) Your codebase then grows proportionally and if your code is understandable even without documentation, you generate duplicate information - scrolling just won't add to the clarity of the code via comments ;)

Find problems in code

If you have doubts about your code, you can ask the AI ​​assistant to try to find problems in it. If you're a nitpicker, you can do the same over code of your colleagues ;)

It is true that developers often let down their guard under time pressure and forget to take care of borderline situations - it is for these cases that I see "find problems in code" as one of the better features of AI assistants.

Copilot chat

Probably the last of the main skills of AI assistants is chat, known for example from Chat GPT. Simply open a prompt and you can ask whatever you want, but keep in mind that the language models of the AI ​​assistants for programmers are not trained on general data - unlike Chat GPT, so they won't talk to you about everything ;)

But he can deal with the programming question without any problems.

AI yes or no?

I recommend everyone to try AI in their work. For senior developers, its value is not that much, but for those who are new to programming, or want to expand their horizons – give it a go! ;)

Most assistants include a free trial version, so there is no spending at all!

I personally use the AI ​​assistant from Jetbrains, but after the initial enthusiasm, I can now use only the following types of assistance: "Find Problems in Code", "Code completion" and "Write Unit Tests" functions.

Jiří Ludvík, xitee Tech Lead

Other blog from the same industry