GitHub Copilot is Autocomplete on Steroids

I cancelled my Spotify Premium, so I could afford GitHub Copilot. I was not disappointed.

I've been using Copilot for a few days now, and it's been a game changer. I've been able to write code faster than ever before. GitHub Copilot has been the best autocomplete I've ever used.

The Good

It Can Write Documentation

This entire post was written on PyCharm, augmented by GitHub Copilot. It's made several assumptions about what I wanted to write. I had to steer it back in the right direction several times.

Copilot Can Write A Lot Of Code

The first "real" project I used Copilot on was a scrapy project. Normally I'd have to copy an entire template from the docs, and then modify it to my needs.

I was able to write the entire spider in a few minutes just by typing scrapy.Spider and then hitting tab. My spider already had some scaffolding filled in, with some object attributes written somewhere in the project (not in the same file).

Copilot was able to find these attributes and fill in my validators, parsing logic, and other boilerplate code with very little input from me. I had to fix some url parsing logic, and add a few more fields to the spider, but that was it.

My scrapy project inserts data to a MySQL database. Guess how much work it took to write the MySQL connector?

All I needed to do was to write the class name-

class MySQLPipeline(object):

and Copilot filled in the rest.

    def __init__(self, host, user, password, db):
        self.host = host
        self.user = user
        self.password = password
        self.db = db

    @classmethod
    def from_crawler(cls, crawler):
        return cls(
            host=crawler.settings.get('MYSQL_HOST'),
            user=crawler.settings.get('MYSQL_USER'),
            password=crawler.settings.get('MYSQL_PASSWORD'),
            db=crawler.settings.get('MYSQL_DBNAME'),
        )

    def open_spider(self, spider):
        self.connection = pymysql.connect(host=self.host,
                                          user=self.user,
                                          password=self.password,
                                          db=self.db,
                                          charset='utf8mb4',
                                          cursorclass=pymysql.cursors.DictCursor)
        self.cursor = self.connection.cursor()

    def close_spider(self, spider):
        self.connection.close()

    # I manually adjusted the indentation and split the query into multiple lines
    def process_item(self, item, spider):
        self.cursor.execute("INSERT INTO `items` (" +
            "`name`, " +
            "`price`, " +
            "`stock`) VALUES (%s, %s, %s) " +
            ", (item['name'], item['price'], item['stock'])")
        self.connection.commit()
        return item

Copilot Reduces Context Switching

Copilot has reduced the amount of context switching I would have done if I were to write this code from scratch.

This would have been my workflow:

  1. Write down a general idea of what I need to do

  2. Open up Scrapy documentation

  3. Copy the template

  4. Write some code

  5. Pull up documentation or StackOverflow to figure out how to do something

  6. Write some more code

  7. Repeat steps 5 and 6 until I'm done

Somewhere in between 5 and 6, I would have been distracted by Reddit, HackerNews, Twitter, or some other website.

This was my workflow with Copilot: 1. Write down a general idea of what I need to do

  1. Open up Scrapy documentation

  2. Copy the template (negligible, I could have just made copilot do this too)

  3. Write some code

  4. When stuck, I just stop typing and wait for Copilot to suggest something

  5. Write some more code

  6. Repeat steps 5 and 6 until I'm done

Copilot has suggested irrelevant stuff in the process.

The Bad

Copilot jumps to conclusions

Copilot has made some assumptions about what I'm trying to write. (Funnily, this line was written by Copilot after I wrote the above)

Examples:

Copilot wants me to give it a shot

Copilot thinks I can't pay $10 a month

Copilot assumes it doesn't disappoint me.. yet

Copilot thinks writing documents is writing code?

Copilot thinks highly of itself

Copilot thinks highly of itself, but you already knew that

Conclusion

It's only been a few days, but I can't imagine not using Copilot for any project. I don't find it reducing mental strain. I still have to review the code it wrote and adjust it to my needs. So far, it's helped with focus and typing fatigue.

This post was created with GitHub Copilot and reviewed by ChatGPT.

tags: code