Debugging CodeLab Submissions With OUTPUT

CodeLab's goal is to offer incisive, on-the-mark feedback for every incorrect student exercise submission. This is an ideal that we're still pursuing. Meanwhile, what is a student to do when the CodeLab response is minimal? What do you with CodeLab responses like

     Your output is incorrect.
or
     The value of total is incorrect.
or
     Your code is incorrect.

Of course you can scrutinize your submission, reread the instructions, go over your notes, check your textbook: all good things to do. But suppose you've done all that. What then?

The OUTPUT Tab. Whenever a submission generates output, an OUTPUT tab appears next to the RESULTS tab. Clicking the OUTPUT tab lets you see all the output that your submission generated.

Seeing your output can be helpful in an exercise where you are supposed to generate output (like one of the "hello world" type of exercises), but what about an exercise where you are NOT supposed to generate output?

Let's use an example here. For reasons of space it will be an extra-simple example. Suppose the exercise called for you to "add two to the variable x". Suppose you wrote:

     x = x + 1;

and suppose CodeLab replied "Wrong value for x, please revise your code."

Now you could make use of the OUTPUT tab. You can stick into the submission statements that write the value of x out to standard output. In Java you might write:

     System.out.println("BEFORE: x = "+x);
     x = x + 1;
     System.out.println("AFTER: x = "+x);

  (In C or C++ you'd use printf or cout respectively.)

When you submit this, CodeLab will still say you're wrong and may even grumble about the standard output that you're writing. BUT! You can now look at the OUTPUT tab and see how the value of x was changed by your code. Once you see your error, you can fix it. BE SURE TO REMOVE OR COMMENT OUT THE EXTRA OUTPUT STATEMENTS YOU ADDED before submitting again.

In the example, generating output may be more trouble than it's worth, but in a loop exercise it could be really useful.