Introducing Computer Science Using A Breadth-First Approach and Functional Programming
Introducing Computer Science Using A Breadth-First Approach and Functional Programming
net/publication/2608274
CITATIONS READS
11 1,529
2 authors:
All content following this page was uploaded by Michael Wollowski on 18 March 2015.
180
it on our departmental server. Chez Scheme is an efficient grammar and the Scheme functions is striking and is a
production version, with customer support and good tracing good demonstration of how theory and practice support
and debugging facilities to help the novice programmer. each other (see Figure 1).
Students can connect to it using X-Windows or Telnet, from The BNF rules in Figure I are adapted from one of our lab
any internet location supporting those modes of connection. exercises and are part of the full BNF for a Scheme
We make syllabi, course assignments, solutions, and review identifier. Each Scheme function in the figure implements
exercises available on a course web page. the corresponding rule in the BNF. (Note that we use
As we shall illustrate below, a breadth-first approach and "first" and "rest" in place of "car" and "cdr", and that we
the use of a functional programming language dovetail quite have omitted several of the BNF rules for brevity.) In this
nicely into a fairly comprehensive introduction to Computer exercise, the students are given the BNF rules and are
Science that contains a healthy balance of theory and asked to write the Scheme functions. Each recursive BNF
practice. The course design is based partly on ideas from rule becomes a similarly reeursive Scheme function and
Computing Curricula 1991 [5] and from a model curriculum each disjunct in a BNF rule becomes a disjunct in a
for a liberal arts Computer Science degree [6]. While not a Scheme function (although we can, in the case of the
programming course, programming is used to educate our "subsequent" function, avoid a direct translation of the
students about the field of Computer Science. Our general third disjunct in its BNF rule).
approach is to cover, each week, certain aspects of
Computer Science and functional programming, and
wherever possible show their connection. 2.1 The Breadth-First Nature of the Course
For example, when investigating language definition and Before introducing this course, our first Computer Science
translation and the role BNF grammars play in them, we course was a standard programming course in which we
have our students implement part of a lexical analyzer for used Pascal. With such a course, students got the
Scheme. The correspondence between rules of the BNF impression that Computer Science is just programming.
Instead, we wanted to give our students a broad
introduction to the major areas of Computer Science,
hoping that this may serve as a framework and context on
which to build for subsequent courses.
<ident> ::= <initial_char><subsequent> In many curricula, including our old curriculum, there is no
single place in which students could construct a picture of
<subsequent> ::= A I <sub_char><subsequent> I <sub_char> Computer Science as a discipline. While a curious student
<sub_char> ::= <initial_char> I <digit> I. I + I - can piece together an idea of Computer Science over a
period of several years of studying Computer Science, such
a process assumes that a student takes a very wide variety
of courses. In practice, this assumption does not always
(define (ident char list) hold. By giving a broad introduction to Computer Science,
(and (initial_char (first char_list)) we ensure that our majors are at least introduced to
(subsequent (rest char_list}))) important Computer Science concepts, such as language
translation, hardware design, history of computing,
(define (subsequent char_list) alternative programming paradigms, etc, which are covered
(cond ((null? char_list) #t) only in upper level electives.
((and (sub_char (first char_list)) Furthermore, our students, like those at many schools,
(subsequent (rest char_list))) #t) were learning recursion late in their second semester then
(else #f)))
promptly forgetting this valuable problem-solving
approach, in part due to the recognized difficulty of
introducing it in a procedural language [2]. Additionally,
(define (sub_char char)
the functional programming paradigm was only seen by
(or (initial_char char) students if they took a programming language or Artificial
(digit char) Intelligence course, whereas the procedural and object-
(eq? char #\.) oriented paradigms were, and still are, covered very
(eq? char #\+) thoroughly later in the curriculum.
(eq? char #\-))) This course is a prerequisite for all our major cemrses and
students typically do not test out of it. Anyone who has AP
credit typically receives credit for our second course. In
the following subsection we motivate the choice of the
Figure 1: Partial BNF and Scheme for Lexical Analysis functional programming paradigm. Following that, we give
a brief outline of the course and describe a specific
181
laboratory as an example of our breadth-first approach to design issues rather than on the intricacies of the syntax
Computer Science with functional programming. and type declarations of procedural languages. This in turn
facilitates the writing of algorithmically interesting
programs fairly early in the course.
2.2 Choice of Programming Paradigm and Language
A pleasant side-effect of the use of Scheme is that almost
The choice of Scheme was motivated by a frustration over none of our freshmen has used or even heard of the
our students' programming habits. Submitted programs language. This course satisfies the college core
tended to contain lengthy procedures (over a page long) and requirement for quantitative reasoning, and as mentioned
hence were difficult to debug and grade. Other efforts [7] earlier, the majority of the students in this course are not
have recognized the need for an appropriate instructional Computer Science majors or minors. The use of Scheme
environment, and our choice of Scheme in a breadth-first, acts as a great equalizer, where a diligent humanities
lab-based course provides such an environment. student can productively participate in class as much as a
In Scheme, the most natural way to program is by designing Computer Science major with a good amount of
small functions, something on the order of one recursion per programming experience.
function. This means that top-down design principles have Since Scheme requires the use of good design techniques,
to be strictly followed. While this design principle was
an introductory course can be set up as a course that
taught even when using Pascal, in Scheme the temptation to emphasizes, among other things, problem solving methods,
violate this principle is much lower than in procedural
starting with a general statement of a problem, down to a
languages. Speculating on the reason for this, it seems that finished program, concentrating on problem reduction
(i) it takes a certain amount of practice to learn how to set methods such as top-down design and reeursion. This
up a recursive function, hence preventing overuse and (ii) it makes it a useful course even for those students who take it
is very easy to set up an additional function and add a call to to satisfy the core. By the end of the semester, our students
it in the function under development. can implement complex and sophisticated programs. Some
Intertwined with problem reduction and the implementation examples from previous semesters include Eliza and
of programs in terms of many small functions is incremental Blackjack.
testing. A benefit of Scheme is that the programmer does
not have to spend valuable time declaring trivial variables
and data-structures. This not only saves time but also 3 Putting it all Together
enables students to easily create test data for individual Figure 2 contains a course outline, listing each week's
functions, without putting them into a larger cluster of Computer Science and Scheme topics. Each week, we
functions that share complex data structures. Given this, we tightly integrate the general Computer Science material
set up lab exercises so that our students indeed test and and the Scheme material, as exemplified in Section 2 with
debug their programs incrementally. the BNF exercise. The remainder of this section is a more
The consequent use of top-down design and incremental extended example of a typical laboratory session.
testing were the primary reasons for choosing Scheme. Each lab session, all of which were written by the authors,
There were, however, other important reasons. The syntactic is split into six sections: goals, background readings,
simplicity of Scheme enables our students to focus on system know-how, expanding general Computer Science
Figure 2: Course Outline (weeks are approximate and expand slightly to a 14-week course)
182
knowledge, developing programming solutions in Scheme, (or (not a)
and short essays challenging students to think critically and (and a (not (and a b))
creatively about issues related to the lab topics. Labs build (not: b) ) )
on knowledge and experience from prior labs as well as on
lecture materials. In addition to Scheme, the labs use the
software that comes with the textbook. This software Figure 4 Figure 5
enables experimentation with many fundamental Computer
Science concepts and visualization of how some aspects of
a computer work. Among others, the textbook's lab manual Figure 5 is a more concise implementation of the circuit in
and software includes simulators for circuit design, a v o n Scheme. This implementation requires a closer examination
Heumann machine, an assembler, and a Turing Machine. of the truth-table for the circuit. A more efficient version
To give a sense of the experimental and collaborative of the circuit itself could have been constructed in the same
nature of the lab sessions, we now describe an actual and manner. By using the circuit simulator and Scheme
representative lab assignment. It is the third lab session of software in this way, students see the relationships between
the semester (usually held during the fourth week of the hardware and software aspects of Boolean logic.
classes) and its goals are to design and test simple In the last section of the lab, students are asked to write
electronic circuits and to practice Boolean logic and short essays based on their experiences with the lab
conditionals in Scheme. software. Since they have been working with a system of
The background for this lab comes from the text, from 2-valued (true/false) logic, we ask them to speculate on the
lectures, and from handouts. The system know-how advantages and drawbacks of a 3-valued system of logic,
section of this lab covers some features of the editor used to assuming the underlying hardware is based on devices with
compose programs and text, a brief introduction to an three, rather than two, easily distinguished states (0, 1, and
electronic mail program that is commonly used on campus, 2 instead of just the 0 and I of binary logic).
and some features of the windowing system software that The lectures and labs are tightly integrated: many topics
can be used to cut and paste text. The fourth section, on are introduced in lecture with online demonstrations and
general Computer Science knowledge, uses the circuit experiments that are continued in lab. For example, to
simulator software provided by the textbook. Students will prepare for the lab described above, we review Boolean
spend 30..45 minutes tracing, modifying, and then logic and introduce the concepts of gates, circuit design,
developing from scratch their own circuits. Figure 3 is a and conditional statements in Scheme. During this lecture,
circuit produced by a student using this software. This we typically use and experiment with truth tables to
circuit is a complicated version of the Boolean function illustrate the operations of Boolean logic and to assist in
NAND which is false if and only if both its inputs are true. circuit design. Truth tables serve to specify circuits. From
These experiments with Boolean logic in a hardware truth tables, circuits can be constructed in an algorithmic
setting are followed, in the lab's next section, by a study of manner. Concurrently, we experiment with conditional
Boolean logic from the programming perspective. Students statements in Scheme and illustrate the use of Boolean
are asked to implement Scheme functions that simulate logic in Scheme. Furthermore, we explain the details and
some of the circuits developed in the previous section of subtleties of the circuit simulator, enabling students to
the lab. Figure 4 is a Scheme function that produces the concentrate on the important issues of design when they are
same output as the circuit in Figure 3. This Scheme in lab.
function is derived from the circuit by a straightforward
translation of gates into equivalent Scheme functions.
4 Experiences
Students have received a broad introduction to Computer
.XAMI }LL.(3[~ Science, strengthened by their hands-on experience with
Rle Gates Changes Grid Scheme and the lab software. The simplicity of Scheme's
syntax allows us to spend half the course time on Computer
Science concepts and allows us to examine the close
relationship between programming and Computer Science.
183
course software has enabled students to work on their College must have a writing component; in this course, the
homeworks and labs assignments (when not completed students write short essays as part of the labs and, of
during the allotted lab time) from any location. The course, write programs.
introduction of recursion has made this topic easier to teach In the future, we plan to make the lab materials available
when it is covered in procedural languages later in the on the world-wide web. We will also be using a new
curriculum. version of Chez Scheme [1] that has support for graphics.
The experimental and collaborative nature of the lab This will make some lab exercises more appealing to some
exercises stimulates active discussions within and between students.
the student pairs and between students and the faculty
instructors. The students feel comfortable approaching
other groups and the lab instructor to discuss their ideas. References
The lab exercises also provide ample opportunities for both [1] Chez Scheme. http:/Iwww.scheme.com
oral and written communication about Computer Science.
[2] Ginat, D. and Shifroni, E. Teaching Recursion in a
It is our students' communication skills, combined with
Procedural Environment - How much should we
their technical skills, that make them effective Computer
emphasize the Computing Model? In Proceedings of
Scientists after graduation. From the faculty's point of
the Thirtieth SIGCSE Technical Symposium on
view, the labs give instant feedback about our students'
Computer Science Education (March 1999), ACM
thinking so that lectures and assignments can be tailored to
Press, 127-131.
the current strengths and weaknesses of the students.
[3] Lewandowski, G. and Morehead, A. Computer
While we chose Scheme primarily for didactic reasons, we Science Through the Eyes of Dead Monkeys:
have come to appreciate the fact that almost nobody has
Learning Styles and Interaction in Computer Science L
used Scheme in high school. This makes the language, and
In Proceedings of the Twenty-ninth SIGCSE Technical
indeed the entire course, a new experience for all students: Symposium on Computer Science Education (February
non-majors do not feel "left out" by not knowing the
1998), ACM Press, 312-316.
programming paradigm or language, and experienced
students learn a new language and a broad overview of the [4] Schneider, G.M. and Gersting, J.L. An Invitation to
field of Computer Science, which they do not get in most Computer Science (2"a ed.). Brooks/Cole, Pacific
high-school (or college) programming courses. Grove, CA, 1998.
[51 Tucker, A.B., Barnes, B.H., Aiken, R.M., Barker, K.,
Bruce, K.B., Cain, J.T., Conry, S.E., Engel, G.L.,
5 Conclusions and the Future Epstein, R.G., Lidtke, D.K., Mulder, M.C., Rogers,
The course has proved to be challenging. Nevertheless, J.B., Spafford, E.H., and Turner, A.J. Computing
enrollments have increased steadily and the course has Curricula 1991. Commun. ACM 34, 6 (June 1991), 68-
succeeded in attracting new majors to Computer Science. 84.
The course gives students an opportunity to assess their
interests and abilities in the field of Computer Science as a
[61 Walker, H.M. and Schneider, G.M. A Revised Model
Curriculum for a Liberal Arts Degree in Computer
whole, not just in programming. After four semesters of Science. Commun. ACM 39, 12 (December 1996), 85-
teaching the course we are confident, based on our
95.
experiences and on student evaluations, that it is an
excellent introduction to Computer Science. We have [7] Ziegler, U. and Crews, T. An Integrated Program
demonstrated that functional programming can be used in a Development Tool for Teaching and Learning How to
lab-based, breadth-first environment to substantially enrich Program. In Proceedings of the Thirtieth SIGCSE
the depth and breadth of topics in a first course in Technical Symposium on Computer Science Education
Computer Science. This particular mix of topics has (March 1999), ACM Press, 276-280.
worked well for us, but other general Computer Science
topics could be substituted for some of these without
greatly affecting the value of the course, as long as proper
support for those topics is in the textbook and/or a
simulation.
The course satisfies the College's quantitative reasoning
core requirement by involving quantitative analysis of
physical and logical systems and a healthy dose of symbol
manipulation, an important aspect of both mathematics and
Computer Science. Symbols are stored in the computer as
quantities, and in Computer Science we certainly reason
about these quantities. In addition, all core courses at the
184