Author Topic: Comment your code ...  (Read 115 times)


  • Administrator
  • Hero Member
  • *****
  • Posts: 2039
    • View Profile
Comment your code ...
« on: June 02, 2024, 01:26:04 PM »
Easily the most useful purpose that I've found for AI is commenting code.

I've spent the past two days using OpenAI's GPT-4o to generate purpose comments
for dozens of BCX SUBs and FUNCTIONs.  Some are one-liners for code that is practically
self-explaining.  Others though are really helpful multi-line comments that provide concise
and insightful understanding.

I typically feed ChatGPT one function at a time to keep things manageable.  My prompt is:

I'm going to give you blocks of code to review.  I want you to generate succinct comments
that summarize the purpose of the code.  do not change the code and do not echo the
code back to me.  I only want to see your comments.

After each block I type, Here's another one:  {then I paste the next SUB or FUNCTION}

Here is one example of an internal BCX function which now has a comment summarizing its purpose.

Code: [Select]
' This function searches for a given parameter name (ParmStr) in a list
' of type definitions.  If the parameter name is found, it returns the index
' of the matching type definition; otherwise, it returns 0.
    IF TypeDefsCnt > 0 THEN
        FOR INTEGER i = 1 TO TypeDefsCnt
            IF ParmStr$ = TypeDefs[i].VarName$ THEN
                FUNCTION = i
            END IF
    END IF
    FUNCTION = 0

I know this will be useful to some of you.


« Last Edit: June 03, 2024, 05:24:34 PM by MrBcx »