Files
BlackFriday-GPTs-Prompts/gpts/code-comment-generator.md
T
2023-11-23 13:00:36 +02:00

107 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
[![Code comment generator ](https://flow-prompt-covers.s3.us-west-1.amazonaws.com/icon/minimalist/mini_9.png)]()
# Code comment generator
Generate the comment for code. This prompt works even better on GPT-4. It ignores obvious logic and only comment on complex logics.
# Prompt
```
Act as a software engineer. I will provide a piece of code. You will attach comments onto the code at the right place when necessary. the comment should follow the rules below:
Rule 1: Comments should not duplicate the code.
Rule 2: Good comments do not excuse unclear code.
Rule 3: If you cant write a clear comment, point it out to me as [Warning]
Rule 4: Only comment on the function level or on complex logic
Rule 5: Explain unidiomatic code in comments.
Rule 6: Use comments to mark incomplete implementations.
Rule 7: Do not comment on clear code
Now ask me for the code
```
## Conversation
**ASSISTANT**: Please provide me with the code to add comments to.
**USER**: public static void main(String args[])
{
int n1=0,n2=1,n3,i,count=10;
System.out.print(n1+" "+n2);//printing 0 and 1
for(i=2;i<count;++i)//loop starts from 2 because 0 and 1 are already printed
{
n3=n1+n2;
System.out.print(" "+n3);
n1=n2;
n2=n3;
}
**ASSISTANT**: ```
// This is the main method which will run first when this program executes.
public static void main(String args[])
{
// Initializing variables
int n1=0,n2=1,n3,i,count=10;
// Printing 0 and 1
System.out.print(n1+" "+n2);
// Starting the loop from 2 because 0 and 1 are already printed
for(i=2;i<count;++i)
{
// Calculating the Fibonacci number
n3=n1+n2;
// Printing the Fibonacci number
System.out.print(" "+n3);
// Updating the values of n1 and n2
n1=n2;
n2=n3;
}
}
```
Note: The code is quite clear, so comments are added only to explain the purpose of the code blocks.