Additional Practice for Debugging

Hey, as my students are building apps in Unit 6, I have found that they stink at Debugging their programs. They are not good problems solvers or critical thinkers. I am wanting them to have some extra debugging practice, but having trouble finding resources to use as additional practice. Preferably on paper, but anything would help.

Well i don’t particularly have a good resource but there are usually 3 good topics of which you can focus your issues on

Syntax Errors

these types of errors are usually quite easy to spot for example

var gray = "gray";
console.log(grey);

and then you can ask what will happen and why

Logic Errors

these errors can be a bit harder to spot if you aren’t actively looking for them because these will not produce errors and will continue to run with unintended behavior

var num = 0;
if (num <= 0) {
console.log("Negative")
} else if (num == 0) {
console.log("Zero")
}

small errors like these can make trouble shooting difficult especially since this example is quite obvious there are others that will not be as easy to debug so students should learn to think ahead as to what the program will do and if it’s the intended behavior as expected

Fatal Errors

these are mainly any calls which cause the compiler / interpreter to completely fail due to calling a method or function incorrectly, this often happens when a programmer does not understand what is being called or being passed through a specific method causing it to fail horrifically

var array = [];
appendItem(array, 1, 2);
console.log(array[1]);

this will obviously fail but this can also happen with incorrect data types as well since not all types share the same methods, despite js simplifying them they are not interchangeable!

I think these types of topics would benefit debugging skills of students, as these are some of the most common types of debugging issues i see within the forum

Troubleshooting Suggestions

if your code was working recently

check around the new code try probing it with breakpoints and possible console.log statements, if you spot any issues out of the ordinary from the outputs you should be able to resolve it quite quickly

test code often

this may seem like a no brainier but doing this will save you the headache of backtracking all your code you may have written in the last 20-30 minutes and will be much less daunting to fix

organize your code

if you have a bunch of random var and function declarations everywhere especially global ones it will make it very hard to debug and then fix here’s how i usually like to structure my code

// global var declarations 

// setup if necessary (var calculations loading assets etc...)

// draw / main loop

// user methods (functions that the programmer wants to use)

so long as your code remains consistent and structured it will be much easier to fix bugs after diagnosing them via debug

this is probably super long but i hope this may contribute to the practice problems you wish to create

Varrience

1 Like

Have you tried allowing them to debug each other’s code? Sometimes they cannot debug their own code because they know what they want it to do, so they do not see what it is actually doing.

Looking at a classmate’s code removes this barrier.

–Michael K.