Saturday, December 27, 2025

AI Written Code and Making Assumptions

I’ve been writing some code for my own amusement the last few days. I have happily using Microsoft CoPilot to help me out. One really has to be careful with prompts though. CoPilot loves to make assumptions about what the developer desires. Often, it assumes correctly. Often enough, it assumes incorrectly.

I spent a good bit of time trying to figure how where it was doing some things I didn’t want done at all and other places where it got my intentions backwards. For example, we both had different ideas about what a variable called _defaultColor should refer to. That took me a bit.

I could have tried to ask CoPilot to fix the problem for me but if I had a better idea of how to express what I wanted it would probably have gotten things right, for my definition of right, the first time. So I fixed it myself.

I also made some assumptions about what certain methods were doing. I mostly assumed correctly but mostly is not really good enough when dealing with code. I really should have spent more time reading the code and making sure I understood it before trying to modify it. Yes, I said it before knowing how to read code is more important than ever.

Reading code on a screen can be painful though. One tends to get a sort of tunnel vision looking at little bits of code at a time. Many years ago I worked with a developer who had a terminal that was originally developed to typesetting at newspapers. It was tall and could hold a lot of lines of code. It was great for reading code. I don’t have anything like that. For me, the answer is printing listings out on paper. Maybe its just me but that is what has worked well for me for over 50 years of writing code.

I have more modifications I want to make to my program. I’ll spend some serious time reviewing the generated code before I try to make those modifications.

Related read: "Source code is the literature of computer scientists." https://www.cs.uni.edu/~wallingf/blog/archives/monthly/2025-12.html#e2025-12-26T18_28_37.htm A post by Eugene Wallingford

One other note, CoPilot added a lot of helpful error handling code to what I asked. That’s awesome in a lot of ways. I think that spotting a lot of error handling code may be something that tips off an educator that a student used artificial intelligence to write their code. Keep a look out and be sure to ask the student to explain it all.

No comments: