ChatGPT as a team member

I have several projects where I am the sole developer, and sometimes that leads to getting stuck and really just needing someone to talk to about the problem. ChatGPT has proven to be an unexpectedly good pair programmer in those situations. I work quite closely with AI and am very impressed with what it can do.

Of course, there are other aids for developers, GitHub’s Copilot is also an excellent support. But Copilot is more of a help to avoid writing something that it can figure out you were about to write, for example, if you’re going to iterate over a list with a for-loop, it gets it right almost every time. ChatGPT, on the other hand, is more like having a colleague, or perhaps more like having a code-writing servant.

Multiple times when I’ve been faced with a problem where I wasn’t sure where to start, I’ve asked ChatGPT for a suggestion. It might look something like this:

I have a two-dimensional array of booleans where each boolean represents 8×8 pixels in an image. How can I create a polygon that outlines the values represented by true in the array?

Almost immediately, I get this answer:

To create a polygon outlining the areas represented by True values in your two-dimensional array of booleans, you can follow these general steps:

  1. Identify the connected regions of True values in your boolean array.
  2. For each connected region, find the outline or boundary of that region.
  3. Create a polygon using the boundary points.

Here’s a simple example in Python using the scikit-image library to achieve this:

followed by fully functional code. But I didn’t want the solution in Python, so I replied with:

Can you please write the code in Go?

There is, of course, no need to throw in courtesies like “please” when talking to an AI, but it replied:

Certainly! Here’s an example of how you might approach this task in Go. This example uses a simple connected component labeling algorithm to find connected regions and then extracts the boundary of each region to create a polygon

The code it gave me was surprisingly good, using no external libs other than a png package to create a png file. However, I didn’t want a file but just a list of coordinates that I could send to an external system, so I continued to talk to ChatGPT.

I don’t need an image, just an array of coordinates that make up the polygon of the areas marked with true

Immediately, I got this reply:

Certainly! Here’s a modified version of the Go code that generates an array of coordinates representing the polygons of the areas marked as true:

It felt here like it was time to test the code, it sort of worked but my polygons didn’t end at the starting point, which I wanted. An easy thing to fix on my own, but just for the sake of it, I asked it to do that:

The polygon should be closed at the end

And with that, it fixed it. It’s actually quite impressive.

That sounds great!

Yes and no, after a day’s work trying to find the perfect solution, you realize that it sometimes goes in circles, it gives up, finds a new algorithm, etc., and when you can’t quite get it to work, you’re met with a:

I apologize for the confusion. Let’s simplify the approach and use the marching squares algorithm to find the contour of the largest connected component. The marching squares algorithm is well-suited for extracting contours from a binary array. Here’s the updated code

Then there is a back and forth discussion, after which it takes a new approach and maybe goes back to the previous solution that still doesn’t work. However, the worst is when it, as all AI does, decides to fabricate and make things up. It often ends up with a solution that doesn’t even compile.

After a while, even I grew tired and decided to ask what I was wondering:

Have you given up?

The reply I got was unexpectedly honest, if you can call an AI honest…

”I apologize for the continued challenges you’re facing with the code. It seems like finding a suitable solution has proven to be more complex than initially anticipated”

and then it gave me a new non-working solution. 🙂

OK, that doesn’t sound great. Was it worth the effort?

Yes, I do believe that, but one must set the bar at the right level. I’ve received variations of 3-4 different proposed solutions that worked to varying degrees. None are perfect, but as I’ve tested them and tried to understand them, I’ve also seen why they fail and I think I’ve found the solution I will use and fix myself. The solution feels obvious at the moment (to a human), but it remains to be seen if it works.

Moreover, it’s enjoyable and one feels a little less lonely when you can ask someone for help even if you’re working on your project alone.