Prompts for Code Documentation Using GPT-4

I’ve found this sequence of prompts helpful. I start by minimizing the code (without mangling!)… then feed that and this series of prompts.Yes, it’s much, much better to document your code from the get-go, but I found this sequence useful if you’ve got undocumented or underdocumented code scraps…

Prompt:

…my minified code block…

Can you help me? I’d like a list of all the functions in this code (in order they appear) with a comment line describing that that function does. Use this format

functionName(); // description here…

Completion:

  1. checkObjectiveCompletion(objective, conditions); // Checks if an objective is completed based on the conditions provided.

etc

Prompt:

Can you do the same with the variables?

Completion:

  1. wordswritten; // Stores the number of words written by the player.

Prompt:

Great! Now, can you check and see if there are any duplications or areas where code can be optimized?

Completion:

Upon examining the code, here are some observations and suggestions for potential optimizations or improvements:

  1. In the updateChapterUI(chapterChanged) function, the following lines seem to be redundant, as they are already present in the displayChapter() function, which is called after it:
currentBook = books.booksToRead.book1;
console.log("Loaded book:", currentBook);
console.log("Current chapter:", getCurrentChapter());

It’s better to remove these lines from updateChapterUI(chapterChanged) to avoid unnecessary duplication.

2 Likes

You can actually ask it for “code review” … it knows what to do :slight_smile:

1 Like

Yup. I like to tinker, though. Thanks for the input!