I’ve got a sneaking suspicion that a mentor has used ChatGPT to critique my code. I can’t prove it and I may be insulting the mentor by suggesting it. It’s just that the mentoring doesn’t seem to line up with the code and has a strange cadence.
For example:
The use of multiple counters in the WS-COUNTERS group (WS-NUMBER-OF-TRAILING-SPACES, WS-LENGTH-OF-PHRASE, WS-LETTER-COUNT) is a bit confusing. It would be better to use more descriptive names for these counters.
I would have thought that the names were very descriptive.
You are using the INSPECT statement to remove trailing spaces, but then using the SUBTRACT statement to calculate the length of the phrase. This is an unnecessary step and can be simplified by using the INSPECT statement to calculate the length of the phrase.
Well, no, I’m not using INSPECT to remove trailing spaces. INSPECT can’t do that. And the method I’m using to calculate the length of the string is well known.
* Get length of sentence
INSPECT WS-PHRASE TALLYING WS-NUMBER-OF-TRAILING-SPACES
FOR TRAILING SPACE.
SUBTRACT WS-NUMBER-OF-TRAILING-SPACES
FROM LENGTH OF WS-PHRASE
GIVING WS-LENGTH-OF-PHRASE.
Similarly,
Instead of using two IF statements to check if the character is not a space and not a dash, you can use one IF statement with a logical OR operator.
I’m not using two IF statements: the code in question is one IF and an AND, viz
IF WS-PHRASE(WS-TEMP-A:1) NOT = '-' AND
WS-PHRASE(WS-TEMP-A:1) NOT = SPACE
ADD 1 TO WS-TEMP-B
MOVE WS-PHRASE(WS-TEMP-A:1)
TO WS-PHRASE-TEMP(WS-TEMP-B:1)
END-IF
I just went to ChatGPT and asked it to critique my code. It gave me similar answers again with the strange cadence. The same mentor gave responses to FORTRAN and Crystal exercises but without the oddities described above.
Has anyone else had a similar experience?