CreatiCode XO (AI Assistant) - Debugging
-
Introduction
One area where almost every student needs help is debugging, and our teachers often do not have the time or expertise 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 it 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 rely on analyzing your code and your input, which is challenging even for experienced programmers. 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”, 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, the expected behavior can be inferred from 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 spot 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.
Note that XO will only report one or two such problems each time to avoid overwhelming you. Also, the problem it reports may not directly resolve the issue you are facing, as there may be multiple bugs in the program. Therefore, you should still fix the problem reported by XO first, then ask XO for more suggestions.
Issues with Using New Blocks
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, it’s essential to first determine where the problem might be coming from by zooming into specific parts of your project.
If you’re not sure which parts of your code to look at first, you can get XO’s help. If you explain the problem well, XO can help figure out the best place to start looking.
As a practice, please open the following project and remix it:
play.creaticode.com/projects/6616a1a7564fc287b0e9b879
Next, modify this block 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:
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:
-