330 likes | 482 Views
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
E N D
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 • Run time • Logical
Debugging Steps • Recognize error • Find the error in the code • Determine how that spot relates to program
Debugger Evolution • Command Line driven • Text for the names and values of variables • Keyboard Input/Text Output • Various breakpoints • Single Stepping • Graphic User Interface (GUI) • Show the code executing • Reveal values of variables by clicking on them • Still just names and values of variables
Current Debuggers • GNU Debugger • DDD • JTracer • SwingDebugger
Visualization • Sight provides the most understanding • For Effective Visualization (Stasko, et al., 93) • Include detailed text instructions • Link with instructional goals • Perform user testing • Include rewind/replay functions
Recursion • A recursive function is one that can call itself • Breaks large problems into small problems • Base cases • Taught early in computer science courses • Taught at Westminster in CS 152, the second CS course
n!=n*(n-1)*(n-2)*…*3*2*1 In recursive form n!=1 if n=1 n!=n*(n-1)! if n>1 In Computer Code Factorial(n){ If(n==1) Return 1; else return n*factorial(n-1); } Factorial Example
4*Factorial(3) 3*Factorial(2) 2*Factorial(1) 1 2 6 2*1 3*2 24 4*6 Factorial Example Factorial(4)
Fibonacci Sequence • 0,1,1,2,3,5,8,13,21,34,55,89,144… • The next number is the previous two added • Fib(n){ • if(n=0) • return 0; • else if (n=1) • return 1; • else • return Fib(n-1)+Fib(n-2); }
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.
The Recursive Debugger • Goal-Visually depict recursive functions • Use of tree structure • Downward branching • Outward branching • Function Box • Parameters, Return values, Received values
RecursionDebugger Class • Software to create, update, and maintain display window • Evolved over 2 semesters • Command line based • GUI based • Requires tags to be inserted in user’s code
Tags • Three classes • Create instance • Gather parameters • Gather return and received values
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 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); • }}}
OpenGL for Java • Debugger required graphics package • OpenGL chosen • Jogl was chosen due to ease of use
Tree Storage • Arrays-too much mapping • Binary tree-not enough children • Three Pointer method-parent, first child, next sibling
Drawing the Tree • when endParameters() and changeCurrentAndReturn() are called • Each box’s placement is relative to parent or sibling • Each box contains two displacement fields • transx • transy
LetterDrawer Class • Jogl lacked text drawing abilities • Implemented class to use OpenGL to draw letters • Translates to appropriate spot • addChar() • Done for parameters, return values, received values
User Features • Step • Run Through • Current Path • Arrow Keys • Center Window
Future Possibilities • Program Rewind • Other language Implementations • Global variables • Multiple recursive functions • Collapsible tree • Automatic Tag Insertion
Conclusions • Met our design goals • Works for a wide variety of recursive functions • Visualization criteria • Include detailed text instructions • Link with instructional goals