Working With AI

It’s been impossible to not have been bombarded with all the hype about AI ever since ChatGPT. There are now several powerful LLM tools available, and one of the claims is that they can write software better than human programmers. As a software developer myself, and one who’s been doing this kind of thing for longer than many of my colleagues have been alive, you might understand my skepticism.

Before I retired, NVIDIA gave all of its employees access to Perplexity Pro, so that’s the LLM I have the most experience with, but I have tried several others. At first I would ask it to write some Python code to replicate a problem I had already solved, to get a feel for how well it did. Most of the time the solution it provided worked, but just didn’t feel “elegant” – it was much more like a beginner would create. But it did work in most cases.

You may have heard the term “vibe coding” used to describe a non-developer using AI to write code. I have tried that, and the results were spotty at best. I decided to write an app for my iPhone that would be useful when practicing disc golf by measuring the distance of a throw. I had no experience with writing Swift or developing with SwiftUI, so it was about as close to vibe coding as I could imagine.

The process was surprisingly quick: it gave me the basics I would need to set up the app, get the mapping tools working, and implementing buttons. It wasn’t smooth sailing, though, as Perplexity would suggest code that was for different versions of Swift, and they would throw errors. I could then copy those errors and paste them back into the “conversation” with Perplexity, and it would respond with a correction (usually preceded by an apology – nice touch!). I did get something working in a couple of days, so I would say it was a success. Adding additional features, such as voice interaction, proved to be a much tougher endeavor; there were just too many incompatibilities that were hit as it tried to write the more complex interactions.

So based on my meager experimental sample of 1, I would say that vibe coding works, but only for the simplest of cases. It felt like asking a machine to design a house: sure, it could probably come up with something boxy that would work, but once you tried to add some style, it would probably mix things up. It’s a language processor, after all, and doesn’t actually understand anything.

Where I’ve found AI to be helpful is when I need to write some code in a language or environment that I don’t work in often, or solve a strange bug. Let me give you an example from yesterday.

I’ve hosted technical email lists on my servers for over 25 years, and I maintain an archive of every message. It’s all automated and generally works well. Each month it analyzes the previous month’s traffic, and posts a summary.

The June summary for the ProFox list came out on July 1, and it was missing most of the messages for that month. I investigated, and found a problem with the archive software that was pretty straightforward to correct. The problem was that I no longer had the original messages to add back to the archive. Some subscribers did, so I was able to add them back – except for one.

The error was clear enough: the text had a smiley emoji, and the MariaDB database column that holds the text of the message was defined with utf8 encoding. Emojis require multibyte (utf8mb4) encoding, so I ran the ALTER TABLE command to change the encoding. This took almost an hour, as the table has over a half-million records that needed to be re-encoded, but when it completed, I confidently re-ran the command to add the message, but once again it failed – with the exact same error! So I turned to Perplexity, fed it the table structure and the error, and it quickly came back with a solution: not only did the column need to be utf8mb4, the entire table has to be defined with that encoding. So once again I ran ALTER TABLE, but it took over 2 hours this time.

When it finally finished, I re-ran the command, and once again it failed, with the exact same message! I read Perplexity’s answer once again, and noticed that I had missed one part of it: defining the connection in pymysql. I needed to also tell the connection to use the correct charset:

    conn = pymysql.connect(
        host=HOST,
        user=creds["DB_USERNAME"],
        passwd=creds["DB_PWD"],
        db=db,
        cursorclass=cls,
        charset="utf8mb4",     <========
        use_unicode=True,      <========
    )Code language: PHP (php)

I had never added those parameters before, as they were never needed – it worked fine with the defaults. But once I added them, the command to add the message worked flawlessly! So in this case, Perplexity saved the day. I’m sure I would have figured it out eventually, but this was so much faster, as Perplexity runs multiple searches on the web and analyzes the responses in order to come up with its answer to your question.

And that’s what machines will always be better at than humans: doing multiple things at once. I could have run those searches, but going through the results to see which matched what I needed would have taken a whole lot longer than what Perplexity could do. That’s the sweet spot for coding with AI: not having it design your application or its interface, but solving those edge case bugs that would take you a much longer time to figure out.

Leave a Reply