0% found this document useful (0 votes)
5 views6 pages

Event-Driven Programming Is Simple Enough For CS1

Computer science data structures and algorithms

Uploaded by

marcusgarxvy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

Event-Driven Programming Is Simple Enough For CS1

Computer science data structures and algorithms

Uploaded by

marcusgarxvy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/220808019

Event-driven programming is simple enough for CS1

Conference Paper in ACM SIGCSE Bulletin · September 2001


DOI: 10.1145/377435.377440 · Source: DBLP

CITATIONS READS
26 1,090

3 authors:

Kim B. Bruce Andrea Danyluk


Pomona College Williams College
155 PUBLICATIONS 3,814 CITATIONS 40 PUBLICATIONS 432 CITATIONS

SEE PROFILE SEE PROFILE

Thomas Murtagh
Williams College
36 PUBLICATIONS 413 CITATIONS

SEE PROFILE

All content following this page was uploaded by Kim B. Bruce on 02 July 2014.

The user has requested enhancement of the downloaded file.


Event-driven Programming can be Simple Enough for CS 1

Kim B. Bruce Andrea P. Danyluk Thomas P. Murtagh


[email protected] [email protected] [email protected]
Department of Computer Science
Williams College
Williamstown, MA 01267, USA

Abstract graphical interfaces have little interest in laboratory


We have recently designed a CS 1 course that integrates assignments based on line by line text input and output.
event-driven programming from the very start. Our There are also those opposed to this approach. Several
experience teaching this course runs counter to the authors have expressed concern that event-driven
prevailing sense that these techniques would add techniques are either beyond the grasp of students in
complexity to the content of CS 1. Instead, we found that introductory courses or would require so much additional
they were simple to present and that they also simplified class time that other, more fundamental topics would be
the presentation of other material in the course. In this displaced. Wolz and Koffman [4] have developed their
paper, we explain the approach we used to introduce “simpleIO” library to enable students to construct
event-driven methods and discuss the factors underlying applications with the feel of a GUI but “without the
our success. complexity of non-sequential models.” Reges advocates a
1 Introduction “conservatively radical” approach in which the instructor
provides students with implementations of the GUI
We recently implemented a major update of our CS 1 components of an application and then asks the students
course. The new version of the course is based on Java to construct classes that interact with the instructor’s [6].
(replacing Pascal), takes an objects-first approach, uses
labs incorporating graphics, and introduces event-driven Even some that advocate the introduction of event-driven
programming techniques including threads quite early in techniques, do so with the assumption that these
the course. techniques are advanced. Although Stein seems to be
quite radical in her call to introduce students to a
Our decision to introduce our students to GUI computing model based on interacting communities of
programming and to use event-driven techniques was processes, event-driven techniques do not appear until
influenced by two arguments. The first, expressed by relatively late in her course. In one draft of her text,
Culwin and others [2, 8, 10], is that “our current students event-driven programming is not covered until chapter 15.
need to be prepared for practicing their skills in the
context of software development in the twenty first It is reasonable to be concerned that event-driven
century.” [2] Teaching them techniques appropriate for programming is too complicated to be presented in an
teletype terminals and card readers not only fails to introductory course. We debated the issue extensively
prepare them with the skills required to understand and before deciding to incorporate the event-driven approach
construct modern systems, but may burden them with from the very beginning of our course. Since then,
techniques that later need to be unlearned. experience offering the course has convinced us that
event-driven programming techniques can be presented to
Others have cited student motivation as their incentive for students in a way that makes them intuitive. Furthermore,
incorporating elements of GUI programming and event- we discovered that the use of an event-driven model
driven techniques in introductory courses [3,5]. Students facilitates the clear presentation of several other, more
accustomed to working with programs with flexible, standard topics.
2 The Evidence
From the very first lab in our course, we have students
construct programs in a framework based on the Java
Applet class. Their first programs are defined as
extensions of a WindowController class from our library
that itself extends the Java Applet class. Our
WindowController creates a specialized Canvas in which
the students can place graphical objects, and it allows
them to handle mouse events by defining event-handling skills considerably weaker than those who take CS 1.
methods with names like onMouseMove and Nevertheless, the use of an event-driven model has also
onMouseDown. These methods are very similar to the been quite successful in this non-majors course. Since
mouse event-handling methods of the Java AWT. The there was no previous version of the non-majors course,
main difference is that they expect simpler parameters. we can not offer any quantitative comparison of student
Most of our event-handling methods receive a single perceptions of difficulty.
parameter describing the coordinates where the mouse Between our CS 1 course and our non-majors course, we
event occurred, rather than a more complex "Event" have observed the reactions of over 200 students to an
object. Our library also provides students with a set of introduction to programming based on an event-driven
primitives to simplify the display of graphics. The model. This experience has strongly confirmed our hope
graphic features of our library are similar to those that this model could provide a simpler rather than a more
described by Roberts and Picard [7]. complex approach to programming for the novice.
In the first lab, students use this environment to construct 3 Some Explanations
a simple drawing that changes in response to mouse
clicks. By the second lab, they have learned conditionals, Our experience has been so contrary to the expectations
allowing them to construct a program that lets users drag of others that it is appropriate to explore this contrast in
objects around the screen to implement something similar more detail. We believe that two factors are responsible:
to a shape-sorter. Next, they learn to write programs (1) We and others have tended to overestimate the
involving several classes. For the third lab, they again complexity of the event-driven model;
write a program that allows users to drag objects around (2) The actual support current systems provide for event-
the screen, but this time there are several objects and they driven programming is more complex than necessary.
interact like magnets. We then introduce loops and a
simple form of threads which they use in lab to create an We suspect that the reason many overestimate the
animated game. After about 6 weeks, we can move difficulty of event handling is that they themselves did not
beyond the simplified interface provided by our library encounter the subject until they were already experienced
and explain standard Java event-driven programming programmers. It is only natural to assume that something
mechanisms. At this point, students also learn how to one learns late in one's training must be advanced.
program with buttons, choice items, scrollbars (sliders), In reality, the absence of event-driven techniques in the
and text fields. training of current instructors was not related to their
The ease with which our students learned to program complexity. It resulted from the fact that situations where
using event-driven techniques surprised even the most event-driven techniques are appropriate, such as programs
optimistic of us. Students with no previous programming based on interactive GUIs, were not common when most
experience found the model completely natural. Those current instructors learned to program. In today’s world
with previous experience had no problem adapting to the full of interactive programs, it is appropriate to expose
approach. In both cases the change had consequences that students to the programming techniques that best suit the
made other components of the process of learning to construction of such programs.
program easier. Most strikingly, the event-driven style We must remember that event-driven techniques were not
nearly eliminated the tendency novice programmers have devised to make programming harder. They were
to construct long, complex procedure bodies, and the developed because they can actually simplify both the
agony students suffer trying to debug such complex code. details and the underlying conceptual model required to
At the end of each semester, students are asked to construct interactive programs.
complete a standardized evaluation form that includes two To make this concrete, imagine a simple, interactive
questions relating to the difficulty of the course. The program that is supposed to merely draw a dot at the
questions ask the students to rate “the amount of work current mouse position each time the mouse is clicked. In
expected” and “the level of difficulty.” Student responses event-driven form using our library, the solution to this
to both questions after the first offering of the new course problem involves a single, short method that is invoked
were 3.7 on a scale from 1 to 5. These responses fall at by the system each time the mouse is clicked. The body
the 75th percentile among the workload/difficulty of the method contains just the code to draw the dot using
rankings for all courses in the college. More importantly, the method's parameters to determine the mouse position.
these rankings were similar to those of a recent offering of The complete Java code required for this program in our
the previous course taught by the same instructor. For environment is shown below:
that class, the ratings were both 3.6 out of 5. class DrawDots extends WindowController {
In addition to using event-driven techniques in our CS 1 public void onMouseClick( Coords mouseLocation ) {
course, we have introduced this programming model in an new FilledOval( mouseLocation, 1, 1, canvas);
introductory course we offer for non-majors. Many of the }
students enrolled in our non-majors course have technical }
A more traditional solution to this problem would require -Define a class of objects that can act as listeners,
a loop that would be executed once per click. Its body - Declare that the listener class implements the
would consist of nested loops that repeatedly do nothing appropriate listener interface,
until the mouse is depressed and released followed by
code to draw the dot. The code for this approach, -Define the method(s) that the listener interface requires,
appropriate for the environment we used in the previous -Create one or more instances of the listener, and
version of our CS 1 course, Pascal and Quickdraw, is - Pass an instance of the listener class as a parameter to
shown below. The inner loops could be replaced by a call the appropriate component's “addListener” method.
to an “awaitClick” procedure with an appropriate library.
With all of this required, it is no surprise that instructors
program drawdots; think that event-driven programming is too difficult for
var mouseLocation: point; novices. If mechanisms for event-driven programming
begin were designed for beginners, simplicity would be a design
while true do goal. Instead, the design goal is to provide the flexibility
required by expert programmers.
begin
When programming with our library, a student is
repeat until button;
provided with facilities that simplify the details of
repeat until not button; handling mouse events. Student programs are extensions
GetMouse( mouseLocation ); of a class that catches mouse events and invokes simple
PaintOval(mouseLocation.x, mouseLocation.y, 1, 1) methods students can override to handle these events. In
end; the first weeks of our course, in fact, our students believe
the only purpose for method declarations is to associate
end.
event-handling code with particular events. It seems
perfectly natural to them that if you define a method
If you run a program like this and ask students with no named “onMouseClick” then the instructions inside its
programming experience what the computer is doing body will be carried out when the mouse is clicked. Most
before you press the mouse, they will give a fairly of these methods take a single parameter describing the
obvious answer: “Nothing.” The event-driven solution point where the mouse event occurred. This parameter
mirrors the students' natural perception of what the gives students easy access to just enough information
computer does while it is waiting. Doing nothing requires about the events to construct interesting programs.
no code. In the traditional version, however, one must
write explicit code to tell the machine to do nothing. This “training wheels” version of event handling is
necessary for the first few weeks of the course. Before
In past semesters, situations like these have been long, however, we are able to expose students to most of
stumbling blocks for our students. We have had to the features of the underlying Java event-handling model.
explicitly teach them to think like computers and take the
view that nothing must be something. With hindsight, we 4 Advantages of “Events-first”
feel it is clearly more appropriate to adopt programming Those who argue against including event-driven
tools that reflect natural human models of the tasks techniques in the first course frequently express concern
undertaken than to adjust the thinking patterns of our that this new topic will displace other, more important
students to fit the limitations of the programming topics. We had a very different experience. Introducing
techniques we present. the event-driven model very early actually made it easier
In many ways, the argument over whether event-driven to teach other critical topics.
techniques are inherently complex is similar to the One of our goals was to teach students basics of object-
argument whether recursive or iterative programming oriented design. One can introduce Java programming by
techniques are simpler. Typically, those who are taught having students construct simple applications. In this
iteration before recursion find recursion mystifying at case, students begin by placing all their code in a method
first. Once recursion is understood, however, it becomes named main. As the complexity of the code increases,
obvious that there are problems for which the recursive students are taught to procedurally decompose their code
solution is far more clear than any iterative solution. into small, logically structured private methods. The
There is an additional, more substantial reason to doubt problem with this approach is that in following it, one is
the feasibility of presenting event-driven techniques in an teaching a procedural rather than an object-oriented
introductory course. Mechanisms for event-driven approach. Students are led to think of methods as a
programming in contemporary programming systems are mechanism to decompose larger tasks rather than as the
not designed for beginners. As a reminder, here is what is means to describe the possible behaviors of an object.
necessary to do event-driven programming in standard In our course, our students never imagined the idea of a
Java: large main program. From the start, their programs were
actually class definitions that consisted of lists of short
method definitions. At first, they thought of each method Java’s object-oriented features, and therefore they
definition as an event handler. They were not conscious introduce these techniques slightly later than we do.
of the possibility of generalizing the use of the class Stein[8] introduces event-driven programming late in her
construct to define new objects. They did, however, view course, and moreover seems more interested in explaining
methods as a means of describing how a single object the event queue and loop rather than introducing event-
(their program) should respond to outside stimuli. This driven programming as a primitive notion.
view remained clear to them throughout the course. After
years of pleading with students writing in Pascal to Our experience has convinced us that early use of event-
decompose their code into shorter procedures, it was driven programming as a primitive notion provides an
shocking to find that this was simply no longer an issue. effective introduction to programming for novices.
In a paper describing experience teaching a course based References
on Stein’s work, Weber-Wulff discusses the frustration of [1] Conner D B, Niguidula D, & van Damm A, Object-
attempting to teach good design habits to students who Oriented Programming: Getting it Right at the Start,
enter a CS 1 course with what they view as considerable Educator’s Symp at the 9th Annual Conf. on Object
experience [9]. In our course, such students were thrilled Oriented Programming Languages, Systems, and
by the power the event-handling model gave them to Applications, Oct. 1994, Portland, OR.
create interactive programs. They never even noticed that [2] Culwin F, Object Imperatives, Proc. of the 30th
they were simultaneously being led to use good SIGCSE Technical Symp. on Computer Science
programming style. It was as if we offered them the Education, Mar. 1999, New Orleans, LA, pp. 31-36.
tightest straight jacket we could find and they responded
by happily asking us to help them put it on. [3] Jimenez-Peris R, Khuri S & Patino-Martinez M,
Adding Breadth to CS1 and CS2 Courses through
The definition of event-handling methods also has the Visual and Interactive Programming Projects, Proc. of
advantage that the introduction of formal parameters is the 30th SIGCSE Tech. Symp. on Computer Science
separated from the introduction of actual parameters. Education, Mar. 1999, New Orleans, LA, pp. 252-256.
Students use formal parameters when defining event-
handling methods, but don’t have to worry about where [4] Wolz U & Koffman E, simpleIO: A Java Package for
the actual values come from. They accept the idea that the Novice Interactive and Graphics Programming, Proc.
system somehow provides this information to their of the 4th Annual SIGCSE/SIGCUE Conf. on
methods. At the same time, they are actively using actual Innovation and Technology in Computer Science
parameters when invoking the constructors and methods Education, June 1999, Cracow, Poland, pp. 139-142.
of our graphics library. By the time we introduced the [5] Mutchler D & Laxer C, Using Multimedia and GUI
definition of new classes of objects, students are Programming in CS 1, Proc. of the SIGCSE/SIGCUE
comfortable with both notions and are well prepared to Conf. on Integrating Technology in Computer Science
deal with the idea that a formal parameter can refer to an Education, 1996, Barcelona, Spain, pp. 63-65.
actual parameter from another part of their program. [6] Reges S, Conservatively Radical Java in CS1, Proc. of
In conjunction with the use of objects through our the 31st SIGCSE Technical Symp. on Computer
graphics library, the event-handling style of programming Science Education, Mar. 2000, Austin, TX, pp. 85-89.
provided an excellent way to prepare students for the [7] Roberts E & Picard, Designing a Java Graphics
introduction of classes. By the time we began asking Library for CS1, Proc. of the 3rd Annual
students to define their own classes, they had already used SIGCSE/SIGCUE Conf. on Integrating Technology
all of the required language mechanisms. Instead of into Computer Science Education, August 1998,
explaining parameter passing or class syntax, we could Dublin, Ireland, pp. 213-218.
focus on the role of objects.
[8]Stein L A, Beyond Objects, Educator’s Symp at the
5 Comparison with previous work 12th Annual Conf. on Object Oriented Programming
Others emphasizing the advantages of event-driven Languages, Systems, and Applications, Atlanta, GA,
programming include Conner et al [1] and Stein[8]. October, 1997.
Conner et al advocate an object-first approach that also [9] Weber-Wulff D, Combating the Code Warrior: A
takes advantage of event-driven programming, though Different Sort of Programming Instruction, Proc. of
they suggest an event-driven model closer to that of Java the 5th Annual SIGCSE/SIGCUE Conf. on Innovation
1.0. Behavior is associated with objects by defining a and Technology in Computer Science Education, July,
subclass of the GUI component. It would seem to be a 2000, Helsinki, Finland, pp. 85-88.
large step to move from this model to the standard Java
event model. In particular, this approach to event-driven [10]Woodworth P & Dann W, Integrating Console and
programming unnecessarily mixes GUI appearance and Event-Driven Models in CS1, Proc. of the 30th
behavior with the application’s structure. Their event- SIGCSE Technical Symp. on Computer Science
handling techniques also require familiarity with more of Education, Mar. 1999, New Orleans, LA, pp. 132-135.
View publication stats

You might also like