Generating Comments
GitHub Copilot is an engine for generating code, but it can also generate comments from code. For example, suppose you have the following code for the Sieve of Eratosthenes without comments:
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 primesGitHub Copilot can write explanatory comments for the method, like this:
# 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 primesAdditionally, it can write code explanations from the code itself, helping engineers quickly understand other people's code:
Displaying Steps
Using the LIST STEPS feature in Code Brushes on GitHub Next, you can achieve similar results.
Code to Document
For large-scale code, one approach is to use tools like ChatGPT or Bing to obtain explanatory output. When you want an overview of the entire code, using chat-style AI tools can be helpful.
Last updated