iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🔨

Trying Out GitHub Copilot in VSCode

に公開
2023/11/09

Initial Thoughts

It's seriously incredible.
Once you use it, you can't go back.

Update

GitHub Copilot has been officially released.
Since this article was written during the beta version, I have added corrections throughout.

How to Use

Please register for GitHub Copilot on the following page (free):

https://copilot.github.com/

Also, install the GitHub Copilot extension for VSCode.

https://marketplace.visualstudio.com/items?itemName=GitHub.copilot

There is a similar name called GitHub Copilot Nightly, but
this is the pre-release version.

You are made to wait a long time after registering.
In my case, I waited for 3-4 months.
The first 60 days are free, and it is a paid service after that.
($10 per month, $100 per year)
You might think it's expensive, but once you read this article,
you'll be like, "Is $10 really enough?"
Also, it is free for students or those contributing to OSS.

Good Points and What's Amazing

Predicts from Comments

In the following code, I only wrote # This def asks for name and age..

# This def asks for name and age.
def ask_name_and_age():
    name = input("What is your name? ")
    age = input("How old are you? ")
    return name, age

Surprisingly Effective Even Without Comments

The following code was generated automatically just with def average or func average.
(average means mean value)

def average(data):
    return sum(data) / len(data)
func average(data []float64) float64 {
    return sum(data) / float64(len(data))
}

Predicts from Variable Names as Well

In the following example, I only entered input_age.

input_age = input("年齢を入力してください: ")

Easy to Read

It is easy to see because it is output in light gray text.

Multiple Answers Available

If there are multiple answers, you can choose from them as shown in the image below.

Truly Understands the Meaning of the Code

In the code below, I only entered def average and print("平均は (The average is), and everything else was automatic.

def average(data):
    return sum(data) / len(data)

print("平均は", average([1, 2, 3, 4, 5]))

Predicts the Rest When Inputting Continuously

Except for the first sentence, I only wrote the language names.

Proguraming Language Comment List

Python: #
Go: //
TypeScript: //
JavaScript: //
Java: //
C: //
C++: //
C#: //
PHP: //
Ruby: #
Haskell: //

Others

For Python, I only typed def prime_number.
For Go and TypeScript, I only typed func and const respectively.

def prime_number(n):
    for i in range(2, n):
        if n % i == 0:
            return False
    return True
func prime_number(n int) bool {
    for i := 2; i < n; i++ {
        if n % i == 0 {
            return false
        }
    }
    return true
}
const prime_number = (n: number) => {
    for (let i = 2; i < n; i++) {
        if (n % i === 0) {
            return false
        }
    }
    return true
}

Copilot must be thinking:

This guy probably wants to write prime number detection programs in various languages using Markdown.

I'm sure that's what it's thinking.

Concerns and Complaints

  • License issues Can be changed via settings
  • Whether the code is correct
  • It sometimes conflicts with code completion
  • It can't predict new languages like Zig
  • etc...

There are often people on social media making a fuss about license issues or the hassle of writing comments, but license issues can be addressed through the settings. Also, even without comments, Copilot can infer from function names and code flow as shown above.

Summary

Use it at your own risk, but you'll gain a partner that's like a psychic. From my experience, it suggests the code I want about 90% of the time. It (might) increase development speed. Once again, be sure to check the code thoroughly.

Promotion

Click here for an explanation of a plugin that makes GitHub Copilot even more convenient.

https://zenn.dev/riya_amemiya/articles/ed4e71fd4108d7

Acknowledgments

Thanks to all of you, as of June 24, 2022, it is ranked 2nd in the search rankings! Thank you so much.

🙇

GitHubで編集を提案

Discussion