Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Animating Programs and Students in the Laboratory James F. Korsh Paul S. LaFollette, Jr. Department of Computer and Information Sciences Temple University Philadelphia, PA 19122 Raghvinder Sangwan Department of Mathematics and Computer Science Shippensburg University Shippensburg, PA 17257 Abstract Program animation is a well-recognized tool for the enhancement of understanding of algorithms and data structures. The difficulty of creating animations, however, has limited the use of animation by students. This is especially so in introductory courses where the students need to concentrate on the material to be learned and should not be distracted by irrelevant details of an animation system. We have developed a prototype system which allows students (or instructors) to create C/C++ programs which are self-animating. Use of this system does not require learning any extra programming skills. Users need only specify which variables and data structures they want to be animated. This is done by declaring those elements of the program to be “selfanimating” types. Typically, this would mean substituting INT for int. Similar changes allow for the self-animation of arrays, structs, and pointers. At present, our implementation supports ints and types derived from ints using pointers, arrays, and structs. The resulting C/C++ program appears in an integrated display environment that provides animation of the selected data items, and also shows the source code with the currently animated instruction highlighted. The environment also organizes program information in a way that is meaningful to the programmer, and allows the programmer to control the degree of detail that he or she wants to see. Our experience has been that students are excited and enthusiastic about this technique. This paper will briefly describe the system and, by using examples, show the ease with which students or instructors can create animations in the laboratory or classroom. Introduction In this paper, we briefly describe our prototype system [14,15] which allows students (or instructors) to create C/C++ programs which are self-animating. We will demonstrate that the system does not require learning an additional programming language and that users need only specify those variables and data structures that they want animated. The resulting self-animating program appears in an integrated display environment which shows the source code with the currently animated instruction highlighted and presents the animated variables and data structures selected by the user, We will show how a student might use the system, and how an instructor might create an animated demonstration. Unlike visual debuggers and program development systems [4,7,8,9,11,12], our system displays the dynamics of a program and the context in which changes to data structures occur. Other software visualization systems [1,2,6,13,16] require that a programmer not only understands the program being animated, but also that he or she be directly involved in constructing the animation itself. The benefits of software visualization can be realized more easily if the task of creating visual representations of programs is transparent. Programmers need only concern themselves with what is to be visualized and not how the visualization is to be accomplished. Others have used the same philosophy [3,5], but our system uses a different approach. It requires only simple syntactic changes, almost entirely in declarations, to standard code. Example from a First Programming Course Consider the following simple program, which might be used, in a first programming course. #include <stdlib.h> #include <iostream.h> int values[10]; int add(int v[], int size); void main() { const int sentinel = 0; int temp, sum; int i, count; i = 0; cout << “Enter a number”; cin >> temp; while ((temp != sentinel) && (i < 10)) { values[i] = temp; i++; cout << “Enter a number”; cin >> temp; } count = i; sum = add(values, count); cout << “Sum is “ << sum; } int add(int v[], int size) { int total, k; for (k=0; k < size; i++) { total = total + v[i]; } return total; } Figure 1 shows the display just as the highlighted while condition is being evaluated for the first time. You can see in the CODE pane the necessary modifications that have been made to obtain selfanimation. #include vc++.h is a statement required by our system. The other changes involve the decision to make the array values, and the variables i, count, sum, sentinel, total, and k self-animating, as well as the parameters of the function sum. Changing the "int" to "INT" in the respective declarations did this. No other changes were necessary to the source code. In addition, the title bar of the CODE pane indicates that the function main() is currently being executed. Notice that the window displays global and local variables in separate panes. It also shows dynamically created variables and function parameters in separate panes. One last pane shows the contents of the call stack. Thus, the global array, values, appears in the GLOBALS pane, while the variables local to main() appear in the LOCALS window. Because the function add() is not being executed currently, its local variables are not visible, since the LOCALS pane always displays the local variables of the function currently executing. The first two locations of the array values are visible and the other entries can be seen by using the scroll bar associated with the array. Because none of the elements of this array have been initialized, a "?" is displayed in each entry. The same is true for the local variables count and sum. The constant sentinel contains its initialized value, 0, and i was set to 0 by the assignment statement. The variable temp was set by the input statement cin >> temp. The OPEATIONS pane shows the evaluation of the first part of the while condition. Just prior to this, the values of temp and sentinel in the LOCALS pane would have been seen flowing into the OPERATIONS pane. The result of the evaluation, true, also appears. In general, an operation involving one or more self-animating variables will be displayed similarly in the OPERATIONS pane. In each case, the operands will be seen flowing from their various memory cells in appropriate panes into the OPERATIONS pane, and the result of the evaluation will flow back to memory cells when the result is assigned to a variable. Figure 2 represents the situation just as the call to the function add has been initiated. The OPERATIONS pane shows the actual value of the parameter count from main(), and the PARAMETERS pane shows the corresponding value of the formal parameter size. This value would have been seen flowing from the OPERATIONS pane. The function being executed, add, appears highlighted at the top of the CALL STACK pane. Parameter passing has been identified as an especially troublesome area for students [10]. In Figure 3, the highlighted statement total = total + v[k]is being executed. The OPERATIONS pane shows the operation currently being executed (+), its operands total and “[3]", and its result, 28. As before, the values in these operands would have been seen flowing from their panes to indicate where they came from. Next the system would animate the assignment of the value 28 to the memory cell total in the LOCAL pane. In Figure 4, the call stack shows that we have returned to main().The return value, 58, appears in the OPERATIONS pane. There is also an unlabelled variable in the LOCAL pane containing the value 58. This is the temporary memory cell which the compiler creates unbeknownst to the programmer and which holds the return value. This unlabelled memory cell, along with sum, will be the operands of the assignment statement that is about to be animated. Figure 4 also demonstrates the options window. Clicking on the options button activated this. It is used to control the amount of detail that is displayed as the program is animated. As shown, the operations button has been selected, allowing the user to select which operations (+, -, etc.) will be animated. Similarly the functions button allows the user not to animate selected subroutines. In this case, main() or add() could have been disabled. The views button allows the user to decide which panes will appear. For example, in animating a tree that is built in the heap, it is sometimes useful to display only the HEAP pane[15]. The miscellaneous button controls other features. We have not discussed the use of color coding or additional highlighting. Neither have we demonstrated the animation of pointers and pointer oriented data structures. These techniques are provided by the system but are difficult to discuss in a static medium such as this paper. At present our implementation supports ints, and types derived from ints using pointers, arrays, and structs. Discussion We hope that it is clear that a student can learn directly from using this system in the creation or the running of a program, and that an instructor can use this system to demonstrate a program. By making careful use of the ability to control which panes, operators, functions, and memory cells are animated, it is possible to either watch an overview of the program in action, or to focus in, for instance, on a single loop control variable. Thus, in the beginning laboratory the student can investigate in detail the behavior of loops and other control structures while in a more advanced laboratory the student can watch the effect of dynamic interaction between algorithms and complex data structures. It is impossible to see from our figures the way in which the system brings to life a program in execution. The context in which changes to variables and data structures occur becomes apparent and tangible. Not only are updated variables and data structures displayed in context, but also dynamic changes in the morphology of complex linked data structures become apparent as they are animated. An example of an AVL tree being created appears in Sangwan, Korsh and LaFollette [15]. We have exposed our system informally to colleagues and students who have uniformly wanted to have this system available for their use in both elementary programming and more advanced algorithm classes. Indeed, the authors in preparing this elementary example were able to observe from the animation itself that they had made a number of errors in the code, such as failing to read a new data value at the bottom of the while loop. References [1] Brown, M. Algorithm Animation: An ACM Distinguished Dissertation 1987. The MIT Press, Cambridge, MA, 1987. [2] Brown, M. "Zeus: A System for Algorithm Animation and Multi-View Editing." In Proceedings of the IEEE Workshop on Visual Languages, Kobe, Japan, October 1991, 4-9. [3] Carlson, P., Burnett, M., and Cadiz J. "A Seamless Integration of Algorithm Animation into a Visual Programming Language." In: ACM Proceedings of AVI'96: International Workshop on Advanced Visual Interfaces, Gubbio, Italy, May 1996. [4] Cox, P., Smedley, T, Garden, J., and McManus, M. "Experiences with Visual Programming In a Specific Domain" Visual Language Challenge '96. 1997 IEEE Symposium on Visual Languages, Capri, Italy, 1997. [5] Haajanen, J., Personius, M., Sutinen, E., Tarhio, J., Terasvirta, T., and Vanninen, P. "Animation of User Algorithms on the Web." Proceedings of VL'97, IEEE Symposium of Visual Languages, IEEE 1997, 356-363. [6] Heltulla, E., Hyrskykari, A., and Raiha, K. J. "Graphical Specification of Algorithm Animations with Aladdin." Proceedings of the International Conference on System Sciences, Volume II, Software Track, Hawaii, 1989, CS Press, Los Alamitos, CA, 40-54. [7] Myers, B., "Incense: A System for Displaying Data Structures." Computer Graphics: SIGRAPH ’83 17, 3, 1983, 115-125. [8] Myers, B., Chandok, R., and Sareen, A. Automatic Data Visualization for Novice Programmers. In: IEEE Computer Society Workshop on Visual Languages, Pittsburgh, PA, October 1988, 192-198. [9] Moher, T. PROVIDE: A Process Visualization and Debugging Environment. IEEE Transactions on Software Engineering 14, 6, 1988, 849-857. [13] Roman, G., Cox, K., Wilcox, C., and Plun, J. "Pavane: A System for Declarative Visualization of Concurrent Computations." Journal of Visual Languages and Computing 3, 1992, 161-193. [10] Naps, T. and Stenglein, J. "Tools for Visual Exploration of Scope and Parameter Passing in a Programming Languages Course." SIGCSE Bulletin, March 1996, 305-309 [14] Sangwan, R. "Algorithm Animation Using SelfVisualizing C." Ph.D. Dissertation Temple University May 1997. [11] Reiss, S. "Working in the Garden environment for conceptual programming." IEEE Software Vol. 4(6), November 1987, 16-27. [12] Reiss, S. "PECAN: Program development Systems that support multiple views." IEEE Transactions on Software Engineering, SE-11(3):276:85, March 1985. [15] Sangwan, R., Korsh, J., and LaFollette, P. "A System for Program Visualization in the Classroom." Proceedings of the twenty-ninth SIGCSE Technical Symposium on Computer Science Education, Feb. 1998 ACM: 272-276 [16] Stasko, J. "Tango: A Framework and System for Algorithm Animation." IEEE Computer 23, 9, 1990, 27-39. Figure 1 Figure 2 Figure 3. Figure 4