the visual debugger for recursive functions by charles nogee advisor: dr. bonomo

26
The Visual Debugger for Recursive Functions By Charles Nogee Advisor: Dr. Bonomo

Post on 20-Dec-2015

219 views

Category:

Documents


0 download

TRANSCRIPT

The Visual Debugger for Recursive Functions

By Charles NogeeAdvisor: Dr. Bonomo

IntroductionIntroduction

Goal: A visual representation of recursive

functionsUses: Pedagogical Debugging

Debugging StepsDebugging Steps

1. Recognize error2. Find the error in the code3. Determine how that spot relates to program

Debugger EvolutionDebugger Evolution

Command Line drivenText for the names and values of variablesKeyboard Input/Text OutputVarious breakpointsSingle Stepping

Graphic User Interface (GUI)Show the code executingReveal values of variables by clicking on themStill just names and values of variables

VisualizationVisualization

Sight provides the most understandingFor Effective Visualization (Stasko, et al., 93)

Include detailed text instructionsLink with instructional goalsPerform user testingInclude rewind/replay functions

RecursionRecursion

A recursive function is one that can call itselfBreaks large problems into small problemsBase casesTaught early in computer science courses

Taught at Westminster in CS 152, the second CS course

Factorial ExampleFactorial Example

n!=n*(n-1)*(n-2)*…*3*2*1In recursive form

n!=1 if n=1n!=n*(n-1)! if n>1

In Computer CodeFactorial(n){

If(n==1)Return 1;

elsereturn n*factorial(n-1); }

Factorial ExampleFactorial ExampleFactorial(4)

4*Factorial(3)

3*Factorial(2)

2*Factorial(1)

1

2*12

3*26

4*624

Typical problems using recursion

Typical problems using recursion

Missing, incorrect, or too exclusive base case Factorial can only work for nonnegative integers

Exorbitant and repetitive branching

The Recursive DebuggerThe Recursive Debugger

Goal-Visually depict recursive functionsUse of tree structure

Downward branchingOutward branching

Function BoxParameters, Return values, Received values

RecursionDebugger ClassRecursionDebugger Class

Software to create, update, and maintain display window

Evolved over 2 semestersCommand line basedGUI based

Requires tags to be inserted in user’s code

Factorial Before Tags added

Factorial Before Tags added

public class Fact{ public static void main(String args[]){ System.out.println(fact(Integer.parseInt(args[0])));} public static int fact(int n){ if (n==1){ return 1; } else{ int val=fact(n-1); return (n*val); }}}

Factorial with TagsFactorial with Tags public class Fact{ public static RecursionDebugger hp=new RecursionDebugger("fact", false); public static void main(String args[]){ System.out.println(fact(Integer.parseInt(args[0])));} public static int fact(int n){ hp.createNewBox(); hp.setNextParameter(""+n, "n"); hp.endParameters(); if (n==1){ hp.changeCurrentAndReturn("1"); return 1; } else{ int val=fact(n-1); hp.updateReceived(val+""); hp.changeCurrentAndReturn((n*val)+""); return (n*val); }}}

Half TimeHalf Time

Debugger WindowDebugger Window

Example Displays-FactorialExample Displays-Factorial

Example Displays-N Queens

Example Displays-N Queens

Drawing the TreeDrawing the Tree when endParameters() and

changeCurrentAndReturn() are calledEach box’s placement is relative to parent or siblingEach box contains two displacement fields

transxtransy

Updating TranslationUpdating Translation

Updating Translation 2Updating Translation 2

Updating Translation 3Updating Translation 3

Updating Translation 4Updating Translation 4

This is where you do the demonstration, Chuck

This is where you do the demonstration, Chuck

Future PossibilitiesFuture Possibilities

Program RewindOther language ImplementationsGlobal variablesMultiple recursive functionsCollapsible treeAutomatic Tag Insertion

ConclusionsConclusions

Met our design goalsWorks for a wide variety of recursive functions

Visualization criteriaInclude detailed text instructionsLink with instructional goals

The EndThe End

“Hail to the King, baby.”

“Good, bad, I’m the guy with the gun.”

“But in my own way, I am king.”

“Gimme some sugar, baby.”