Predict the Future
OzCode performs predictive analysis of code execution (or as we like to call it: Fortune telling!)
OzCode predicts the future! You'll see an arrow pointing to where we’re going to go when we hit F10, and irrelevant code paths are made semi-transparent. Predict brings a new meaning to the term “Living Coding”ת by giving you instant feedback on changes you make as you’re debugging, allowing you to fix silly little coding mistakes extremely quickly.
In order to run this demo click the Predict button in the demo application.
You should stop at the beginning of a method.
Place a breakpoint at the line of the switch statement and continue the debug run (F5).
Once you reach the breakpoint you may notice a few things: The case that will be taken is the only one not grayed out (Gender.Female), and there's an arrow pointing to the beginning of that case.
Continue running - the next time the debugger stops at the breakpoint, the grayed out sections will change to show the next executed instruction - case Gender.Male in this case.
Press F10 to move to the next instruction, and the if clause should light up. The red represents conditions that failed, while the passing (true) conditions are marked in green. All of this is analyzed before the code runs.
Since the total result of the four conditions is true, a green 'V' appears near the if and a yellow arrow appears near the beginning of the clause body.
Now add a breakpoint at the beginning of SendThankYouLetter(Customer customer)
And Run until you stop at the beginning of the method - can you spot the bug?
If you're using VS2015 you'll be able to use Edit & Continue and replace the '>' with '<='.
Press F5 to continue debugging. The next time you reach the method another problem will arise. OzCode knows that the next instruction executed will cause a NullReferenceException. The origin of that exception is marked in Red (EmailAddress).
Now that we know what the bug is, it's easy to fix it by making sure that the if clause can handle null email addresses.