コメント生成

GitHub Copilot はコードを生成するエンジンですが、コードからコメントを生成することができます。 例えばコメントがない以下のようなエラトステネスの篩のコードがあるとします。

def eratosthenes_sieve(n):
    primes = []
    sieve = [True] * (n + 1)
    for p in range(2, n + 1):
        if sieve[p]:
            primes.append(p)
            for i in range(p * p, n + 1, p):
                sieve[i] = False
    return primes

GitHub Copilot は以下のようなメソッドの解説のコメントを書くことができます。

# Write the description of the method here <- [Actual Prompt]
# Input: n - the number of primes to return
# Output: a list of the first n primes
# Example: eratosthenes_sieve(5) -> [2, 3, 5, 7, 11]
# Note: this is a very inefficient way to find primes, but it is easy to understand
def eratosthenes_sieve(n):
    primes = []
    sieve = [True] * (n + 1)
    for p in range(2, n + 1):
        if sieve[p]:
            primes.append(p)
            for i in range(p * p, n + 1, p):
                sieve[i] = False
    return primes

また、コードからコードの解説を書き出すことができ、エンジニアは他の人のコードを早く理解することができます。

ステップの表示

GitHub Next の Code Brushes にある LIST STEPS 機能を使うことで、同様のことが可能です。

Code to Document

コードが大規模な場合、ChatGPT や Bing などを使って解説の出力をもらうのも一つの方法です。 コード全体の概要を知りたいときはチャット形式のAIツールを使うと良いでしょう。