Matomo

Debugging with ChatGPT in Informatics

· 5 min read
Debugging with ChatGPT in Informatics

In informatics, work is often done with so-called "worked examples". In programming, for example, videos show exemplary programming processes that students must follow and recreate until they (hopefully) slowly become able to create a new code themselves. In this process of learning the programs, there is a certain amount of mental work involved in acquiring the programming language's syntax, especially if the language is text-based. The process often causes frustration in some students because something as simple as a misplaced comma or a single typo can cause the code to malfunction. 

Most programming environments will help the user find errors in the code, but the messages that are supposed to help the user are not always easy to understand. This article shows how typical problems in working with programming can be remedied with ChatGPT. Also, regarding debugging (debugging) in informatics, ChatGPT can contribute positively to students' learning processes.

Below is an example of JavaScript in the App Lab programming environment (from code.org). The example is taken from a working example from the MyApp YouTube channel:

In this example, the student has to create a small program to convert kroner into euros after entering the number of kroner and pressing a button. But in the above code, it is not the content of the variable **euro** that is inserted as a result, but instead the text string "euro", regardless of what amount in kroner has been entered. The mistake is that there are quotation marks around the euro. This error often occurs because the setText() function in App Labb initially comes with the text "text" enclosed in quotation marks when using that particular block of code:

When you then press "text", what you type will be between the two quotation marks. Even if students watch a video where the two quotation marks have been deleted, there is a risk that students will not notice it. Then, when students run the code, they will often be frustrated with why the program misbehaves. In App Lab, you can see that something is not quite as it should be, as in this case, there is a yellow triangle in line three. If you hover your mouse over the triangle, you will get the text:

Few students will fully understand what it means, and even fewer will probably understand that something needs to be changed, not in line three, but in line four.

Of course, students can always ask their classmates or the teacher for help, but alternatively, they can use ChatGPT to help find the error in the code. Working in App Lab requires students to switch to text editing and then copy the code into ChatGPT:

ChatGPT has caught and managed the bug more easily than App Lab to convey how to fix the error. (When ChatGPT types "line 5," it's because it counts the line: "Can you find the error in the code?" with.) To learn a little more about why the error is corrected in this way, we can ask in the following way:

We get a nice explanation of the difference between how a variable and a text string syntactically differ from each other in JavaScript and even a reference to the variable **euro** in line four.

Let's take another example from the same code, but this time, the error is a simple input gesture in line three (in the picture), where the variable name should be lowercase:

The help texts that come if you hover your mouse over the square or triangle are still not entirely easy to understand. This time, however, we also get help with an outright error message when we try to run the entire code:

However, the error message can still be difficult to understand because it is in English and does not provide an actual solution. Furthermore, it becomes even more difficult if students have not been introduced to what a "string" is. Instead, let's try asking ChatGPT again:

ChatGPT finds the error, describes it in easy-to-understand English, and gets a solution. If the student is unaware of why it is important to pay attention to whether to use uppercase or lowercase letters, ChatGPT may be asked this:

ChatGPT explains exactly why care should be taken with small and large characters when programming in JavaScript.

I hope to have shown with the above examples how ChatGPT can be used by students in trying to lessen their mental work and the accompanying frustrations they have to go through in learning the syntax of a programming language.


Related articles:

Domænekendskab i databasemodellering med ChatGPT i informatik
Et af de vigtigste aspekter af gymnasiefaget informatik er at få eleverne til at forstå og skabe digitale artefakter. Skabelsesprocessen af digitale artefakter indeholder tit en modelleringsproces – en proces, hvor en virkelighed (ofte kaldet for et domæne) skal analyseres og abstraheres og derefter…
Lær Unity med ChatGPT
I HTX-fag som kommunikation og it A, og især i teknikfaget digital design og udvikling, er der mange der kaster sig over spiludvikling i Unity. Der er givetvis også nogle der benytter Unity i informatik eller måske i teknologiforståelse i grundskolen - og jeg ved at Coding Pirates også bruger