How to stop ChatGPT Hallucinations ruining your code (*bonus tip - code better generally)

Panther28

Elite Member
Executive VIP
Jr. VIP
Joined
May 2, 2010
Messages
9,937
Reaction score
16,038
If you are tired of chatgpt mixing up all kinds of things in your code there is a simple solution.

TDD.

Test driven development.

Its where you write tests and your code in conjunction with each other. Then you can run tests in your ide, and see green tick boxes, for every pass, and a failure log and notice for ones that don't.

I got chatgpt to write me an analysing function to test my functions for esmodule and common js (I want only commonjs) and now when I run the tests first, I can see if the file is being recognised by the function, and is valid. (if it hallucinates the wrong code, and I don't notice, I detect it early.)



AD_4nXeoxPyFfWMJ3ZSG-ValKgbu_wlGqBubcpaT6UBa2jG8QF3yIXEBGVuN4Y1d8YmVdTsegni_POWHK7qrAcdX5Vela9oDnPkHnz61fZXrNVN8ZT8xtzPXXWAfw46LEwNAwbtOCfNF


AD_4nXdNd5x3NT30-h8I5iY8ckniOwzlFTk2a6gCybdz_1Yxrt-tWiLdTEkzJn4_UA5O5dqzyA2XrvYJDlHDQWPV8geWpXSyQJcyeIbaCDdDuFv07-jagmKVbsTsdDABEgbatToaVRnY


AD_4nXdF6nkKAKOrLQ2iIOP6BOQjDUME9TaXhkonwrjUMjI4yoTGUJb65Xe4InjsNOsnxa-Tk1CDiYLLg93falbCyYqcLSkXXD5vSQsz_BICmm7RX-qYDhDhWmIHSMdfmbdDGxpgzGKfxw


Have a go at using tests if you don't already, I think there are some ideas that will even write them from your code. They are essential to keeping your development time to a minimum.
 
unit testing and end2end testing is the dullest things i had to do ( in a previous job back then )
dont get me wrong, its great, it prevents problems, its helpful and all.

but its like flossing. you know you should do it but given the choice u would rather do anything else...
 
If you are tired of chatgpt mixing up all kinds of things in your code there is a simple solution.

TDD.

Test driven development.

Its where you write tests and your code in conjunction with each other. Then you can run tests in your ide, and see green tick boxes, for every pass, and a failure log and notice for ones that don't.

I got chatgpt to write me an analysing function to test my functions for esmodule and common js (I want only commonjs) and now when I run the tests first, I can see if the file is being recognised by the function, and is valid. (if it hallucinates the wrong code, and I don't notice, I detect it early.)



AD_4nXeoxPyFfWMJ3ZSG-ValKgbu_wlGqBubcpaT6UBa2jG8QF3yIXEBGVuN4Y1d8YmVdTsegni_POWHK7qrAcdX5Vela9oDnPkHnz61fZXrNVN8ZT8xtzPXXWAfw46LEwNAwbtOCfNF


AD_4nXdNd5x3NT30-h8I5iY8ckniOwzlFTk2a6gCybdz_1Yxrt-tWiLdTEkzJn4_UA5O5dqzyA2XrvYJDlHDQWPV8geWpXSyQJcyeIbaCDdDuFv07-jagmKVbsTsdDABEgbatToaVRnY


AD_4nXdF6nkKAKOrLQ2iIOP6BOQjDUME9TaXhkonwrjUMjI4yoTGUJb65Xe4InjsNOsnxa-Tk1CDiYLLg93falbCyYqcLSkXXD5vSQsz_BICmm7RX-qYDhDhWmIHSMdfmbdDGxpgzGKfxw


Have a go at using tests if you don't already, I think there are some ideas that will even write them from your code. They are essential to keeping your development time to a minimum.
there is better method xD
do not use chagpt but claude ;)
 
1745750349645.png


Seems like years ago i first first posted this thread! lol I had to start over fresh, so this is my code, got about another 25-35 files to go, Then back to paired test programming.

Defiantly helps you stay confident writing tests, as chat gpt or whatever ai you use, will come back with better and quicker suggestions than you.

However sometimes they don't always work first time (really duh? :) ) like I had a file that took me 6 hours to figure out the workings to get the tests to pass, then it took me less than 10 minutes on the bounce from 3 files in a row, that all worked instantly.
 
there is better method xD
do not use chagpt but claude ;)
Exactly - ChatGPT is very good at anything but coding. For coding, Claude is x10000 better, but for writing Claude generally suck balls...
 
Back
Top