Sunday, February 18, 2024

AI Debuggers?

A meme was posted (by Doug Peterson I believe) asking why if the computer knows there is a semi colon missing that the computer doesn’t add it? It’s a good question and I think it gets asked pretty often. The answer is that the computer doesn’t always know where exactly the semi colon belongs. Or if there are other possible answers to the error.

Compiler parsers aren’t always helpful as we’d like. There are several parts to most compilers or interpreters. Parsing is the most visible of these parts. Typically, compiler developers seems to spend the most time and effort on the backend part that generates the actual executable code.  There has been amazing progress in backend code generators. It is unlikely that even the best assembly language programmer can do better than compilers except in rare cases.

The front end, the code parsing that shows syntax errors has not been as big a focus. That seems to be changing and I expect that the inclusion of artificial intelligence may help improve things.

I experimented a bit this morning using Visual Studio. I entered some erroneous code and looked at the results. The code I used was a missing semi colon and a loop with no executable code.

for (int i = 0; i < 10; i++)

I was given the expected “; expected” but I also received a message that “
Error    CS1525    Invalid expression term '}'  “

This is a case of one mistake creating two different errors. This can be pretty confusing.And is less than helpful. Visual Studio did give me a couple of options to deal with this error. Or two. Some of the options didn’t make the errors go away. The one that did was not to add a semi colon but rather to add braces. Of course, either adding a semi colon or adding curly braces leaves one with a a for loop that doesn’t do anything. A warning about that would be nice and I have seen that warning from other parsers.

I would think that a good AI that understands compiler errors would be a lot more helpful. Microsoft is talking a lot about adding artificial intelligence to more products. Will that include compiler/parsers? I think that is likely at some point.

So far the attention has been focused on using AI to generate code. People seem to think that will mean no need for human programmers. People also think that AI will generate perfect code. Or at least code without syntax errors. I think those are somewhat mistaken assumptions. We have lots of great tools for generating websites for example. There are still many cases where human editing of HTML files is needed to get all the desired results.

I expect that human coding for fine tuning of AI generated program code will be necessary for many years to come. As long as AI generated code is “taught” from Internet available code I expect syntax errors to still show up. Some of those errors may not even be caught by parsers. Different versions of compilers can have different rules about what code is acceptable. We will have to see how things progress.

Syntax debugging will be the easy part relatively speaking. Logic errors will be harder still. We live in interesting times.

No comments: