Using AI for programming

I use ChatGTP 4o as a programming assistant these days. It’s to create a web interface for a plant database for our regeneration, reforestation, and food forest project in the Andes. (Google Sheets + Google Apps Script.) In general, I find the AI assistance very helpful. I am also using it to fill in the information for the database, including ranking plants on a variety of dimensions. This info needs to be checked for accuracy, of course, although it generally looks pretty good.

AI PROGRAMMING PRACTICES

First, a few things I have learned about working with an AI programming assistant.

In general, as with all programming, it’s important to be methodical, do it stepwise, and communicate clearly with your programming assistant or partner.

At the beginning of any new dialog, I give the AI any relevant files and ask it to analyze and examine the project. It helps me, it may help the AI, and it helps identify things that can improve the coding or user interface, including finding duplicate code.

Stay on topic. I keep different subprojects in different dialogs. If I have a question not directly related to the current dialog, I start a new dialog for that question. (In a different tab.)

If the current dialog has been going on for a while and/or the AI starts to forget or mix things up, I start a new dialog for a fresh start.

Since it takes a while for ChatGPT 4o to generate a response, I typically ask for only the section of code that’s updated. That makes it go faster. I’ll ask for the full file if there are several updates throughout the same file, or if I am not sure if the AI is working with the same version of the file as I do.

Sometimes, I ask the AI to give suggestions without producing any new code. This can be helpful with troubleshooting, and for finding a strategy to implement a new complex subproject.

I stay involved with the troubleshooting. The AI seems to have a one-track mind to troubleshooting and tends to repeat the same strategy over and over. So I like to take a step back. I examine the code and give suggestions for other things to try. I ask the AI for ideas of other things to try. I often scrap what we did, go back to a clean version, and ask it to try a different approach. (The last one seems to work the best.)

It’s important to stay involved in general. I like to know roughly how it all works and where the different types of code go and help oversee the implementation and troubleshooting. As mentioned in other places, it will sometimes create duplicate code, put code in a place where it doesn’t fit in terms of the file structure, forget that a file exists, remove vital existing code, and so on.

I am in Europe these days, and I find that working with ChatGPT 4o in the mornings European time works the best. In the evening – after the whole of North America is awake – it seems to slow down and often freezes.

When ChatGPT 4o overloads from what I assume are too many people using it, it freezes, cannot reload, and/or it starts giving weird responses. If that happens, it’s a sign to take a break.

Update: It seems that as the project gets larger and more complex, ChatGPT 4o is no longer able to keep track of the different parts of the code and where it’s located. I need to oversee and direct more in detail and only give the files and sections of code relevant to what we are working on in the moment.

This is all not so different from working with a human assistant or in a team with other humans.

Of course, this is all related to my experiences with ChatGPT 4o. Other AIs may need a slightly different approach, and I am sure much of this will change in the future. For instance, I imagine the AI’s ability to keep track of the project as a whole, troubleshoot, and choose a different strategy when one doesn’t work, will all get better.

PROGRAMMING PRACTICES IN GENERAL

In addition to this, general good programming practices are helpful, of course.

I like to include file information in a comment at the top of the file. This describes the file name, its purpose, and the steps, and it helps me keep track of the different parts of the project. Who knows, it may also help the AI.

When I get a new piece of code, I like to check to make sure it goes into the correct file. I have also learned to regularly ask the AI to check for duplicate code in the files.

Since this is a relatively large project, I put the different types of code into separate files. (HTML, styles, front-end scripts, back-end scripts, scripts for search and sort, and so on.) This prevents any one file from getting too big, and it’s more clear where to put and find the different types of code. (Also, I don’t go overboard with this. In some cases, it makes sense to keep it all contained in one file.)

I make small and incremental changes, one bit at a time. This makes it easier to identify any problems.

I keep track of the versions (deployments). I write down the most recent version that works well and sometimes add a brief comment about what works and what’s left to work on. If something goes wrong and it gets too complicated to figure out, go back to the most recent deployment that worked well and start over with a different approach.

I use extensive logging during development. This helps the troubleshooting.

After I implement something new, I test the website to make sure everything else still works.

I find that if I do this when I am hungry or tired, it tends to not go so well. It’s better to eat, rest, and continue later. It’s amazing how something can be fixed after a good meal or a good night’s sleep.

I expect most of the time to be spent on the fiddly little details that don’t quite work. (The 80-20 rule. 80 percent of the project takes 20 percent of the time, and 20 percent takes 80 percent of the time.)

This is just good programming hygiene in general.

The screenshots are from my current project. The first is one page of the web interface. The look and content is still very rudimentary and needs to be refined. The second is a screenshot of the AI filling in a few columns in the spreadsheet. The third is the code used to retrieve image URLs from Wikipedia to be used to illustrate the text.


INITIAL DRAFT

A FEW THINGS I HAVE LEARNED FROM USING AI FOR PROGRAMMING

I use ChatGTP 4o as a programming assistant these days, to help me create a web interface (Google Apps Scripts) for a plant database (Google Sheets). This is for our regeneration, reforestation, and food forest project in the Andes.

Here are a few things I have learned:

Include comments at the beginning of each file with the file name and the purpose and function of the file. That helps avoid confusion.

When getting a new code, check to make sure it goes into the file it’s supposed to. Also regularly ask AI to check for duplicate functions in the files.

Separate the different types of files – HTML, styles, front-end scripts, back-end scripts, scripts for searching and sorting, and so on. This prevents any one file from getting too big, and it’s more clear where to put and find the different types of code. (Also, don’t go overboard with this.)

Make small and incremental changes, one small bit at a time. That makes it easier to identify any problems.

Keep track of the versions (deployments). Write down the most recent version that works well and include a few comments. If something goes wrong and it gets too complicated to figure out, go back to the most recent deployment that worked well and start over and do it in even smaller steps.

Use extensive logging during development. This helps the troubleshooting.

After implementing something new, check the functionality of everything to make sure it still works.

Don’t do this with hunger or tiredness. Eat, rest, and continue later. Also, expect most of the time to be spent on the little fiddly details that don’t quite work. (The 80-20 rule.)

This is just good programming hygiene in general.

A few things directly related to working with the AI:

At the beginning of any new dialog, give the AI the list of relevant files and ask it to analyze and examine the files. It helps me and, I assume, the AI and it can identify problems like duplicate functions.

Avoid confusing the AI. Keep the different subprojects in different dialogs. Start a new dialog for questions that are not directly related to what you are working on in the current dialog.

If the AI starts giving weird responses, start a new and fresh dialog.

When it gets complicated, ask the AI to examine the files and give suggestions without producing any new code. That can help with complex new projects, and also troubleshooting.

Stay involved in the troubleshooting. The AI seems to often have a one-track mind to troubleshooting, so take a step back and look elsewhere too. Also, ask the AI for other possibilities for where the problem may be. Use logging for each step in the process. Try different methods to achieve the same. If stuck, scrap it, go back to a version that works, and find a different approach to do what you want to do.

Stay involved in general. Know how it all works and help oversee the implementation and troubleshooting of new subprojects.

Also, it seems that ChatGPT 4o is frequently overloaded. It freezes, cannot reload, and/or gives weird answers. If that happens, take a break.

Of course, this is all related to my experiences with ChatGPT 4o. Other AIs may need a slightly different approach, and I am sure this all will change in the future as well. For instance, I imagine the AI troubleshooting will get better.

….

There are also some pitfalls, and I am learning to be a better team with ChatGPT 4o.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.