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

The Visual Debugger for Recursive Functions

  • Upload
    asa

  • View
    42

  • Download
    1

Embed Size (px)

DESCRIPTION

The Visual Debugger for Recursive Functions. By Charles Nogee Advisor: Dr. Bonomo. Introduction. Goal: A visual representation of recursive functions Uses: Debugging Pedagogical. Definitions. Program Programming Language Compilers/Compile time Runtime Errors Compile time - PowerPoint PPT Presentation

Citation preview

Page 1: The Visual Debugger for Recursive Functions

The Visual Debugger for Recursive Functions

By Charles NogeeAdvisor: Dr. Bonomo

Page 2: The Visual Debugger for Recursive Functions

IntroductionIntroduction

Goal: A visual representation of recursive

functionsUses: Debugging Pedagogical

Page 3: The Visual Debugger for Recursive Functions

DefinitionsDefinitions

ProgramProgramming LanguageCompilers/Compile timeRuntimeErrors

Compile timeRun timeLogical

Page 4: The Visual Debugger for Recursive Functions

Debugging StepsDebugging Steps

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

Page 5: The Visual Debugger for Recursive Functions

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

Page 6: The Visual Debugger for Recursive Functions

Current DebuggersCurrent Debuggers

GNU DebuggerDDDJTracerSwingDebugger

Page 7: The Visual Debugger for Recursive Functions

VisualizationVisualization

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

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

Page 8: The Visual Debugger for Recursive 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

Page 9: The Visual Debugger for Recursive Functions

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); }

Page 10: The Visual Debugger for Recursive Functions

Factorial ExampleFactorial ExampleFactorial(4)

4*Factorial(3)

3*Factorial(2)

2*Factorial(1)

1

2*12

3*26

4*624

Page 11: The Visual Debugger for Recursive Functions

Fibonacci SequenceFibonacci Sequence

0,1,1,2,3,5,8,13,21,34,55,89,144…The next number is the previous two addedFib(n){ if(n=0) return 0; else if (n=1) return 1; else return Fib(n-1)+Fib(n-2); }

Page 12: The Visual Debugger for Recursive Functions

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 Fibonacci requires calculations to be repeated.

Page 13: The Visual Debugger for Recursive Functions

The Recursive DebuggerThe Recursive Debugger

Goal-Visually depict recursive functionsUse of tree structure

Downward branchingOutward branching

Function BoxParameters, Return values, Received values

Page 14: The Visual Debugger for Recursive Functions

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

Page 15: The Visual Debugger for Recursive Functions

TagsTags

Three classesCreate instanceGather parametersGather return and received values

Page 16: The Visual Debugger for Recursive Functions

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); }}}

Page 17: The Visual Debugger for Recursive Functions

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); }}}

Page 18: The Visual Debugger for Recursive Functions

Debugger WindowDebugger Window

Page 19: The Visual Debugger for Recursive Functions

Example Displays-FactorialExample Displays-Factorial

Page 20: The Visual Debugger for Recursive Functions

Example Displays-MergeSort

Example Displays-MergeSort

Page 21: The Visual Debugger for Recursive Functions

Example Displays-N Queens

Example Displays-N Queens

Page 22: The Visual Debugger for Recursive Functions

OpenGL for JavaOpenGL for Java

Debugger required graphics packageOpenGL chosenJogl was chosen due to ease of use

Page 23: The Visual Debugger for Recursive Functions

Tree StorageTree Storage

Arrays-too much mappingBinary tree-not enough childrenThree Pointer method-parent, first child, next

sibling

Page 24: The Visual Debugger for Recursive Functions

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

Page 25: The Visual Debugger for Recursive Functions

Updating TranslationUpdating Translation

Page 26: The Visual Debugger for Recursive Functions

Updating Translation 2Updating Translation 2

Page 27: The Visual Debugger for Recursive Functions

Updating Translation 3Updating Translation 3

Page 28: The Visual Debugger for Recursive Functions

Updating Translation 4Updating Translation 4

Page 29: The Visual Debugger for Recursive Functions

LetterDrawer ClassLetterDrawer Class

Jogl lacked text drawing abilitiesImplemented class to use OpenGL to draw

lettersTranslates to appropriate spotaddChar()Done for parameters, return values, received

values

Page 30: The Visual Debugger for Recursive Functions

User FeaturesUser Features

StepRun ThroughCurrent PathArrow KeysCenter Window

Page 31: The Visual Debugger for Recursive Functions

This is where you do the demonstration, Chuck

This is where you do the demonstration, Chuck

Page 32: The Visual Debugger for Recursive Functions

Future PossibilitiesFuture Possibilities

Program RewindOther language ImplementationsGlobal variablesMultiple recursive functionsCollapsible treeAutomatic Tag Insertion

Page 33: The Visual Debugger for Recursive Functions

ConclusionsConclusions

Met our design goalsWorks for a wide variety of recursive functions

Visualization criteriaInclude detailed text instructionsLink with instructional goals