Anger and joy...

Anger. ChatGPT loses the overview of several classes

It's easy to work with ChatGPT on small pieces of code: "write this", "change that" works nicely. However I noticed that when we're coming to something like 5 classes and you work on all of them, the AI gets confused.

For example, I was working on two classes: Creature and Element. The two classes are completely unrelated. Still, when I first discussed Element with ChatGPT and then wanted a change in Creature it messed things up and recommended things like:

"To do this, you can define a static traits object in the Creature class that maps each trait to a bit key. You can then define a getBitKey method in the Element class that returns the bit key for a given character."

This is just nonsense. 

And it reminded me a trying to create complex scenery in Stable Diffusion where it can't keep separate characters in a scene apart. 

Now the question is: can I create a more structured approach where I tell ChatGPT that it needs to keep track of the independent files? 

As a first step I took the plunge, shelled out $20 for the plus license and am now a proud user of ChatGPT4.

Then I started with a new conversation. From now on all my experiments are with the AI's version 4.

Joy - ChatGPT refactors two classes

I confess: I did what all newbie developers do. I took a piece of ChatGPT created code in one class and copied it over to another class, instead of trying to figure out how to reuse it properly.

Time for ChatGPT to refactor it.

So I wrote:

Please keep in mind the implementation of DungeonEntityInfo. I have another class, and I'm reusing some of DungeonEntityInfo but have copied a part of a method from it which is ugly, so I would look forward to a suggestion how to reuse this code instead.

And added the code of the whole class there, which contained a method that started with the same code that is also in DungeonEntityInfo.

ChatGPT then 

  1. had a look and found the pasted code
  2. extracted it into a new method in DungeonEntityInfo
  3. changed the code there to call it instead of the pasted code
  4. changed the import in the other class
  5. changed the code in the other class to call the method as well

Pretty nice refactoring job, the two changed classes worked perfectdly.

 

 

Kommentare

Beliebte Posts aus diesem Blog

ChatGPT as a teacher

How it started...

Pathfinding and A*