Debugging Event-Driven Programming
Total Page:16
File Type:pdf, Size:1020Kb
Debugging Event-Driven Programming James Davis Virginia Tech Blacksburg, VA, USA [email protected] ABSTRACT Event-driven programming (EDP) is a natural way to struc- The importance of the event-driven programming (EDP) ture IoT applications [4]. However, little research has been paradigm is on the rise. While EDP has been been common invested in EDP pedagogy or process. If we don’t understand in client-side applications since around 2000 (e.g. GUI de- how to teach the IoT in general and EDP in particular, or velopment, JavaScript-driven web pages), it has only recently how developers conceptualize EDP programming, the IoT vi- entered the mainstream in the settings of mobile computing sion may not be realized to its fullest potential. Techniques (Android, 2008 [15]) and server-side programming (Node.js, from Human-Computer Interaction can inform these questions 2009 [18]). The EDP paradigm is also a natural way to struc- facing EDP. ture applications written for the burgeoning Internet of Things. However, little effort has been invested in understanding the A brief introduction to event-driven programming processes programmers use to develop and debug EDP ap- Many universities dedicate much of their computer science plications or in developing effective educational approaches curricula to procedural (imperative) programming, a sequential for EDP. This research proposes to “debug event-driven pro- or multi-threaded programming paradigm in which programs gramming,” exploring the mental processes EDP developers follow a procedure (sequence of steps, “recipe”) in a relatively use to grok their code and considering contextualized educa- linear fashion until the completion of their algorithm [60]. The tional approaches based on the students’ backgrounds. As a EDP paradigm [26] differs significantly, being non-sequential result, educators and systems researchers will be able to make (asynchronous) and relational (webs of event handlers). I informed decisions about the design of curricula, languages, anticipate that these differences make EDP different to teach, development environments, and debugging aids. learn, and practice than procedural programming. ACM Classification Keywords The EDP paradigm is coming into its own. Though historically K.3.2. Computer and Information Science Education: Com- EDP has played second fiddle to procedural programming, the puter science education; D.2.5. Testing and Debugging: Test- explosion of the event-driven Node.js server-side JavaScript ing tools (e.g., data generators, coverage testing) framework [18] has demonstrated its relevance to applications running on the modern Internet. In an EDP system, the sys- tem defines the set of possible events (e.g. “mouse click” or Author Keywords “incoming network traffic on port 1234”), and the developer IoT; Event-driven programming; Education; Debugging; supplies a set of “event handlers” (also known as “callbacks”) Tools to be executed when particular events occur [60, 24]. During execution in an EDP application, events are generated and INTRODUCTION then routed to the appropriate handlers. The Internet of Things (IoT) holds tremendous promise for human society. Thanks to low-cost sensors and ubiquitous EDP has been used at the level of hardware interrupts since the internet connectivity, IoT devices can make smart decisions early days of computing, but to the best of our knowledge it based on real-time sensor input and advised by intelligent first saw high-level use in the Mesa programming environment. services in the cloud [35]. Nascent IoT systems are already Mesa was an early GUI system, and application developers transforming cities like Barcelona and Singapore, and more could register event handlers for events like the re-sizing of a advanced IoT systems could revolutionize areas as diverse as window [63]. EDP still holds sway in GUI environments, for homes, transportation, and health care [6]. example in the obsolete Java/AWT GUI framework [69] and the now popular Java/Swing and JavaFx GUI frameworks [20, 59]. EDP was later applied in early web servers, as researchers realized that it was particularly well suited to I/O-bound work like that of an FTP server. In this setting, network traffic is translated into client requests, which are “emitted” as events to be handled. For an FTP server, client requests are for files stored in the servers file system, so the handler would submit Contact [email protected] for permission to make copies of all or part of this work. request(s) to the file system, registering yet another event CS5724’16, Fall 2016, Blacksburg, VA. Copyright © 2016 James Davis handler to be executed once the file system completed the request. Until the file system finished its request, the server Novice programmers could process other requests in a similar fashion. In this way, Research on professional programming practice has been a single-threaded event server can handle multiple clients at paralleled by research on the practices of true novice pro- once, with minimal overhead and high performance under grammers. This line of research considers novice program- certain workloads [52]. mers, which are students in their first or second computer science course (CS1 or CS2). Research in this area stud- ies the ways novice programmers interact with source code WHAT WE KNOW ABOUT PROGRAMMERS and programming aids while programming and debugging, There is a rich literature on programmers: the kinds of bugs typically relying on deep investigations of a small group of they produce, how they debug, and the differences between students. Though the programming languages have changed novice and expert programmers. Much attention has been paid from COBOL and BASIC to Java, the findings of the earlier to the kinds of bugs produced by novices (e.g. [56]), as these generations of researchers have been replicated by more recent bug classifications can be used as a feedback mechanism to work. refine the content presented in a course. Other work has gone into debugging techniques, examining debugging both as a The study of the bugs created by novice programmers was specific form of troubleshooting [40] and as a skill to be taught spearheaded by Spohrer and Soloway, who argued that an em- in its own right [5]. pirical understanding of novice bugs would lead to improved courses. They structured their paper around two pieces of folk wisdom: that most errors are due to a small number of root Expert programmers causes, and that most errors are due to misunderstandings of Research into how programmers debug began in the 1970s, the programming language. Their data agree that a few root beginning a long tradition of work on expert programmers. causes explain most errors, but basing their work in GOMS Gould and Drongowski initiated the field, assessing expert philosophy [38] they argue that programmer errors are due to programmers in industry [28, 29]. Their employer, IBM, was the programmer’s incorrect goals and methods unrelated to understandably interested in understanding how its profes- language misunderstandings [61]. sional programmers did their work. They “seeded” one-page The oft-cited work of Katz and Anderson discussed four ex- FORTRAN programs with errors and studied 30 and 10 ex- periments with between 10 and 40 participants enrolled in a perts as they debugged them. Using a combination of notes CS2 course. The most common bug location strategies these and think-aloud, they found that certain types of bugs were students used were “simple recognition”, “forward-looking” harder to identify than others. approaches like hand simulation, and “backward-looking” ap- Ten years later, Vessey compared the debugging processes of proaches like causal reasoning (reason backward from output). “novice” and “expert” professional programmers, using multi- Of particular interest were the findings of their third experi- page COBOL programs seeded with errors. Vessey found ment, which showed that students take different bug location that experts outperform novices, noting that experts seemed strategies depending on whether or not they are familiar with to be better at “chunking” a program: experts could divide a the code. Students took forward-looking approaches when program into its related components more readily than novices, working with unfamiliar code, preferring backward-looking allowing them to focus on the chunks relevant to the bugs [65]. approaches for code they understood [40]. We note that these “novices” are professional programmers, Perkins and Martin studied 20 high school students in their not to be confused with the research on true novices in the second semester of a programming course [55]. By monitoring university setting. This research is discussed below. each student’s performance as they completed a set of asterisk- Eisenstadt provided a qualitative description of debugging printing problems, they found that these novice programmers in industry [22], collecting “debugging war stories” from 78 often ran into problems attributed to their “fragile knowledge”. professionals. He reported commonalities in the stories: many Correct programming relies on the successful integration of a of these experts employed data gathering approaches (e.g. rich set of concepts, and partial, hard to access, or mis-applied printf) and hand simulation to better understand the program knowledge often tripped up these novices. and the cause of the bug, and half of the bugs were cases in Ahmadzadeh et al. innovated a two-pronged approach to study- which the professional tools (e.g. debuggers) available to the ing CS1 students: they assessed both programming practice developers were useless due to significant spatial or temporal over the course of a semester and debugging skills in a 2-hour gaps between a bug’s root cause and its symptoms. exam. From this rich dataset they showed that good program- Inspired by Eisenstadt’s discussion of the importance of data mers (as measured by course grades) are not always good gathering, and the use of information foraging in earlier work debuggers! This finding shows that students don’t always by Russell et al.