Google Bard and Chat-GPT (among other LLMs) can be used for many things. Some of the more productive uses include automating commenting for programming code.
In this post, I will show various examples of how Google Bard can be used to generate comments for software developers.
C/C++
For the examples, we will use a simple program written in C:
#include <stdio.h>
int main() {
int i;
for (i = 10; i >= 0; i--) {
printf("%d\n", i);
}
return 0;
}
This code works by using a for loop to iterate from 10 to 0, inclusive. For each iteration, the code prints the value of the loop variable, i
, to the console.
The Prompt:
Bard’s Response:
It works best when submitting a single function at a time. It also helps to describe what the overall program/module does. This helps Bard create a more coherent output tailored to your specific code.
Python
The code used in this example is a function from an AI Image Up-Scaler program I wrote using Python. This specific function is called as part of the MQTT on_message callback event.
The Prompt:
Bard’s Response:
Bard does a decent job cleaning up the code, using better spacing, providing comments as requested over each line of code.
It also does a good job correctly guessing what each line of code does.
Overall, I believe using Bard and Chat-GPT to refactor code can work to help speed up the process of formatting the code.