Pointer Error Logging &mdash
Towards an Improved Pedagogy for Teaching Pointers in C++
Final Report
Project Overview
Pointers are used in software to indicate the positions of actual data. Good management of pointers is often crucial in dealing with software resources, especially memory. Software developers who do not understand pointers thoroughly can make critical mistakes, so it is important to teach the students who will become those developers how to handle pointers. In computer programming classes, pointers have always been a difficult concept for students to learn and for instructors to teach. Furthermore, the error messages that students encounter while working on programming assignments are often unhelpful and serve only to confuse the student. There has been very little literature written on the methods for teaching this topic, and no "correct" method can be agreed upon. The purpose of this project is to gain a better understanding of these issues in an effort to address some of the problems traditionally linked with the teaching and learning of pointers, and ultimately improve the teaching of pointers in computer science classes.
Research Process
The project lasted for one academic year. Because OSU is on the quarter system that means it spanned three quarters, Autumn 2006 through Spring 2007.
Pointers at Ohio State University
At The Ohio State University, we use a special "checking" implementation of pointers in C++ that allows us to provide detailed and descriptive error messages to students working on assigned labs. Our infrastructure also lets us anonymously record all run-time pointer errors made by the students. For the past two years, the errors made by students on labs dealing with pointers were logged in a database.
Pointer Error Analysis
During the first quarter of the project (Autumn 2006), we analyzed the errors recorded over the previous two years graphically and some distinct trends were found in the types of errors that most frequently occurred during the labs. To follow up with our analysis of the data, instructors who currently teach or have in the past taught classes in which these labs are assigned were consulted for their perspective. Their responses gave us some insight into common student practices when working on the labs and how those practices could lead to the generated errors. In addition, some instructional slides used in the class were changed to reflect the information derived from the data, and instructors were asked to make a point to discuss the most common occurrences of errors.
Student Reports
During the second quarter of the project (Winter 2007), we tried to gain a better understanding of how students approach the lab assignments involving pointers and what misunderstandings and misconceptions about pointers lead to errors. One of the instruments we employed was to ask students working on a pointer lab assignment to record and report what kind of errors they experienced and how they ultimately fixed them. Analysis of the students' reports allowed us to identify several key problems that students encounter, and the responses confirmed some of our previous suspicions. Perhaps most important is the confusion about the concept that a pointer is a reference and does not contain the data item itself. Memory management also seems to be a point of concern. Two of the most common pointer errors recorded are “dereferencing dead pointer by using *” and “creating memory leak by pointer leaving scope”.
Pointer Quiz
In the third and final quarter of the project (Spring 2007), we developed a quiz with multiple choice questions intended to target those areas of confusion and misunderstanding about pointers that we had previously identified. The goals here were (1) to verify that indeed our analysis of pointer errors and student feedback was realistic, (2) to gauge the quality and effectiveness of how pointers are taught at OSU, and (3) to identify remaining problem areas in need of improvement.
The same quiz was administered twice: once just after pointers had been covered in the classroom, and a second time after students had completed three assignments involving pointers (a closed lab in which students implement a stack component as a singly-linked list, and two lab assignments in which students implement a list component as a singly-linked list and a two-way list component implemented as a doubly-linked list).
Quiz Results and Analysis
The quiz produced some interesting results. The results of the first offering seemed to confirm the accuracy of our earlier analysis. Students had trouble distinguishing the pointer from the value referenced, and recognizing memory leaks and other problems caused by aliasing. This also seem to suggest that there might be room for improvement in how pointers are presented in class. The results of the second offering of the quiz showed a marked improvement in all but one of the questions. For the most part, these results seem to indicate that, as expected, lab practice helps students to better understand key concepts and that the programming assignments currently employed achieve reasonable improvements.
Among the potential confounding factors we should note the fact that the data was collected from three distinct sections of the course each taught by a different instructor and also the relatively small sample size. In particular, the one question in which no improvement was observed was the one that dealt directly with the distinction between a pointer and the object referenced by the pointer (Question #1 in the quiz). It turns out that only one of the three instructors uses, as one of the explanations for pointers, a description of a pointer as a memory address, and students in this section actually did show some improvement in their answers to this question. The other instructors relied on metaphors or graphical depictions of pointer and pointer structures. This may account for lack of improvement in the answer to this question and seems to indicate that metaphors and other high-level explanations of pointers may not be sufficient to clarify in students' minds the distinction between pointer and pointed object.
Conclusions
Overall we would say that the current structure of the class seems to work well. The students learn both practical and conceptual knowledge from the laboratory exercises, which was something we had at first questioned. With the tight schedule our courses are already on, it would be difficult to spend more time teaching pointers, and probably not necessary. We have come to the conclusion that, as with many things, practice really is the best answer and students get enough practice by working on the labs. We feel that there is no easy way to make sure every student understands and is proficient with pointers. Our only recommendation would be that the basics are clarified enough so that students can build on solid knowledge. Perhaps more discussion on the fact that pointers represent memory locations of data could help students distinguish between the reference and the object referenced by it.
Lessons Learned
In our research we have learned that when analyzing data it is very important to look at it from more than one perspective. We also learned the value of working with individuals experienced in the field being researched, as they can provide valuable insight and timesaving tips. As our project progressed, our frequent meetings and revising of strategies helped to keep us on task and up to date. We were surprised with unexpected difficulties in data collection, as there was a problem with students accidentally getting the answers to a lab assignment we wanted to test. Because of that, we had to be flexible enough to work with the information we had and to find other ways to obtain the information we wanted. In addition, we really enjoyed the opportunity to get our feet wet in the research and conference arenas and to discover what it was like to present our research.
Publications/Presentations
- Project website: www.cse.ohio-state.edu/europa/CREU/
- Poster presentation at the Ohio Celebration of Women in Computing 2007 conference (Mt. Sterling, Ohio, February 16-17, 2007, www.cse.ohio-state.edu/ocwic/index.html)
- Poster presentation at the Ohio State University Denman Undergraduate Research Forum 2007 (Columbus, Ohio, May 16, 2007, http://denman.osu.edu/)