English Русский Alexander Fenster

1. A Few Words About GitHub Copilot

I stopped writing a blog when Google+ was shut down in April 2019. After that, I kept posting to some private Facebook groups and participated in some Telegram chats, but I really wanted to have my own place to write random thoughts. I also did not really want to depend on any existing third-party service, and even less I wanted to setup WordPress, or Drupal, or anything else and then figure out how to deal with it, keep installing updates having no understanding what's going on inside that thing.

Long story short, I knew I just needed to create my own small cozy blogging platform, but I couldn't push myself hard enough to go write the code.

And then, suddenly, Microsoft shipped Copilot. In case you haven't heard, it's a Visual Studio Code plugin that helps you write the code, or actually, sometimes just writes the code for you. I read a few posts about it here and there, and it was unclear if it's in fact useful or not, and if I need to start thinking about getting a new profession because the artificial intelligence is already good enough so it can program.

So I finally opened my laptop and, with Copilot's help, spent several evenings to make a simple website, the one you're reading now, using Node.js, Express.js, and Firestore. It will make perfect sense to talk about Copilot in my very first post here.

All screenshots in this post are mine, made on my personal laptop.

The scary part

Yes it's really as bad as they write in the internet:

checkPassword function returns true

I made up this example, but you get the idea: you need to be on guard all the time. Copilot is a kind of apprentice who is really inexperienced, so if you don't look, it will do something unexpected, scary, or completely unacceptable, like suggesting to store your password in plaintext:

suggesting to store a password in plaintext

To be fair, it also suggested an option to use bcrypt.

Add a few more very naive examples, and you can quickly conclude that this thing is completely useless. Seriously, i < value?

a function to check if a given number is prime checks while i < n

Or, how about this one:

Fibonacci numbers, recursive implementation

So the first conclusion: do not use Copilot for solving easy algorithmic problems, and always check the result.

Better examples

It does not take too long to realize that one thing where it is really good is that it knows how to use many real APIs, because it actually learned on thousands of the real code samples. It's the main thing here. If you have at least a very basic understanding how the given API works, Copilot's hints will make your coding amazingly fast.

You want to save session key to Redis?

save session key to Redis

You want to read a document with the largest ID from Firestore?

read a document with the largest id from Firestore

In other words, you save a lot of time on reading API samples, passing the right parameters, and getting the call result from the right field.

For this post, I want to show how a real development with Copilot could look like. Let's make a primitive short links service, storing the links in Redis. On the following GIF I'm showing the main part; the full screen recording is published on YouTube.

developing shortlink service

What is bad then?

Everything that is not directly related to writing code is not too good. Copilot speeds up just this one process: coding – you know, writing some characters in a text editor. If you need to change something, you go ahead and fix your code manually. You cannot ask it to change all your functions to pass db as the first parameter; no way, you go and do it yourself, one by one.

Copilot won't write code for you if you don't understand what you want to get. Well, actually, it might as well write some code, but it definitely won't work. In the above example I did not remember how to parse the JSON body of the Express request and I was not exactly sure I know the Redis API, but I had an idea of what I want, so Copilot was able to assist. If you don't know what you want to achieve, the result will be unpredictable, awful, and most likely won't compile.

(Did you notice how it forgot to close the brackets in app.get('...', (req, res) => { ... });?)

Copilot can suggest some piece of code that is just a little bit wrong, and if you are not paying attention, you have a problem. This is especially true when it suggests a regular expression; you need to literally check it character by character to make sure it does exactly what you need, and not something else.

What is good then?

It's really great in automating some uncool parts of your code. You don't need to procrastinate anymore if you need to write some CRUD or anything like that.

It's important to note that I'm mostly talking about my use case here, which is hobby coding. I write code for myself on my personal laptop in my free time, I don't normally publish it anywhere, so it feels pretty safe. I don't recommend to use it for anything serious, or for helping with your work. But as a fun thing to use in my free time, it's a wonderful thing.

And finally

It can write anything, not just the code. Yes I am a software developer, but no, I'm not a student at the UW.

random English text

About / Disclaimer