CreatiCode XO (AI Assistant) - Debugging
-
Introduction
One area where almost every student struggles is debugging, and teachers often do not have time to help every student with it.XO can fill the gap by assisting each student to diagnose their program and brainstorm how to fix it.
To understand how XO can help in the debugging process, please read “how to debug” to understand debugging in general. Otherwise, you may not use XO most productively to help you debug.
Important Note: Do not rely solely on XO to fix all issues in your code. The most effective debugging methods often require running the program and observing the outcome. However, XO can not execute your code, so it has to work with you to understand where the problem is. Additionally, the current version of XO has limited capabilities in logical reasoning and error detection. Consequently, the primary responsibility for identifying issues rests with you, and XO should serve merely as a supporting tool.
Explain “Expected vs Actual” to XO
As you may already know, debugging is all about finding out why the actual outcome of the program is different from our expectations.
A common mistake when using XO for debugging is failing to explain this difference. Beginners tend to say these to XO: “It is not working”, “What’s wrong”, “Check my code”, or “Help me debug”. These requests are not helpful since XO doesn’t know what outcome you are expecting..
Also, XO can only read your code (as opposed to running it), so it does not know what you actually observe when the program runs. When it is not clear what’s the issue, XO will ask for clarification:
It is recommended that you always include these 2 parts when starting a debug request:
- What I expect the program to do
- What I observe when the program runs
Here are some good examples:
- I expect the Dog to say 1 to 10, but it only says 1 to 8
- I am trying to move the clone to a random position, but I see that it always appears in the same position
- I thought the list would contain 10 numbers, but when I ran it, I only got 1 number
Sometimes, XO can infer the expected outcome based on your description, so you may omit that part. For example:
- The chatbot never responds to my question -> implying we expect the chatbot to respond in a short time
- The sprite doesn’t move, why? -> implying we expect it to move
- The 3D table’s top is not connected with its legs -> implying we expect the table top to connect with the legs.
XO can find common bugs
For small and common coding mistakes, XO can spot them right away. For example, here is a simple program with a variable initialization bug. The “set counter to 1” block should not be inside the loop. XO not only points out the issue, but also suggests how to fix it.
Issues in New Block Usage
The CreatiCode playground offers many new blocks compared to MIT Scratch, and XO understands all of them, so it can point out issues associated with their usage. For example, here is a common issue in 3D programs about loading a 3D model:
Narrow Down the Problem’s Scope with XO’s help
For more complex issues in larger projects, it is likely that XO may not see the issue either. In these situations, you need to identify where the issue is, and XO can help you in this search.
If you’re not sure which parts of your code to look at first, explain the problem clearly to XO, and XO can suggest the best place to start looking.
As a practice, we will make a buggy program intentionally, then practice finding it. First, please open the following project and remix it:
play.creaticode.com/projects/6616a1a7564fc287b0e9b879
Next, modify this block towards the bottom to set the y speed to -450 instead of 450, which will be the bug we try to find.
Then you can ask XO to help locate the issue like this: The cube is not jumping up. Where should I look into?XO will suggest a few relevant places:
You can then ask follow-up questions about any of these suggestions.
Ask XO how to add logging
Logging is another commonly used debugging technique. If you are not sure where to add the print blocks or what to print, you can also ask XO to help you.
For example, suppose we have a simple program with a small bug like this:
We can tell XO this: I want to add print blocks to help me debugAs a result, XO will suggest where and how to add the new print block:
Debugging in the Socratic Mode
When XO is not in the Socratic mode, it will try its best to tell you what and where the bug is if it can find it. When it does not know the answer, it will suggest what you can do to search for the bug.
This is very helpful when you are stuck on a problem for a long time and there is no one to help you. However, your brain is not getting trained to identify or search for the bug yourself, so you don’t learn this skill when you rely on XO all the time.
When XO is put in the Socratic mode, it will refrain from telling you the bug directly, even if it already knows about it. Instead, you will be in charge of searching for the bug and fixing it, and XO will serve as an assistant in this process.
Therefore, it is strongly recommended that you learn to debug issues in the following way:
- Start debugging the issue yourself, without XO’s help
- If you are stuck, ask XO to help in the Socratic mode
- If you still can not find the answer, ask XO to help in the non-Socratic mode.
-
info-creaticode