Saturday, June 24, 2023

Thought process blackholing - ChatGPT to rescue

During course of Software development, our thought process will get stuck many times, and we need to take a break or need help from other engineers to get out of it. This state is common, particularly, while troubleshooting a bug or a failure scenario. In this blog, I am taking such an example, and how ChatGPT can help in faster resolution.

This was sometime last year, where there is a software failure occurring on a rare condition. We were not able to reproduce the issue at will nor able to find any issue in the code. The Senior developer, my co-worker, was looking at the code for more than 2 days, and he didn't find any issues in the related APIs. Then we jumped on a call, and I pointed out the code where there is bug, and was able to solve it in 10 minutes. The software bug looks something like the following.

wg := new(sync.WaitGroup)

go func() {

     wg.Add(1)

     fmt.Println("Hello world")

     wg.Done()

}

wg.Wait()

fmt.Println("Execute after func is done")

In the above code, func go-routine can be scheduled at any time and wg.Add may not be run, so the parent code can print "Execute after func is done" before "Hello world". The issue is obvious here, but hard to find it in a blob of code. The fix is simple, move wg.Add(1) before the go func(){} body or after it.

This thought-stuck state happened to me as well, many times in the past. I had to take a break from looking at the code or need some external trigger to clear the state. 

A very-smart static analysis tool can help here, but static analysis is always on the back burner when we have high-priority tasks. 

ChatGPT for rescue. I quizzed ChatGPT to find out what the above code is doing. Here are my interactions with it.

ChatGPT explains what the code is trying to do




With my next level of probe, it finds the bug. I think the probe can be automatic so that ChatGPT can find it while explaining.




With ChatGPT integrated in developers' IDE, we can fix this issue while coding, or alternatively hook up the ChatGPT in the code review process which can do better review and find the bug before merge!

I believe tools like ChatGPT can only make developers' life easier, and make us more productive!




No comments:

Post a Comment