what happens after python in cs1? - CiteSeerX

5 downloads 3530 Views 138KB Size Report
Consortium for Computing Sciences in Colleges. To copy otherwise, or to republish, requires a fee and/or specific permission. 7. WHAT HAPPENS AFTER ...
WHAT HAPPENS AFTER PYTHON IN CS1?* Joseph D. Oldham Centre College Danville, KY [email protected] ABSTRACT In 2000 – 2001 Centre College began using Python as the first language in a breadth first CS1 taken by both majors and non-majors. Shannon described that course our choice of Python for that course in [5]. At this point all matriculating students in our program used Python as a first language in that CS1 course. In general we are happy with the choice, and we have the experience to say why. We can also point out some issues that have arisen as a result of the choice. INTRODUCTION Centre College began using Python as the programming language in CS1 in the 2000-2001 academic year. At present all matriculating students began in Python. During summer of 2004 our program committee undertook a curriculum review, with eyes cast toward both CC2001 [7] and the LACS model curriculum [1]. We concluded that we are satisfied with the choice of Python, and we were able to understand why. We were able to note cases where our choice of Python contributed to issues later in the curriculum, and were able to discuss how we address or could address those issues. Our purpose in this paper is to share those observations. Our observations are anecdotal. Our program is not large enough to present a meaningful quantitative analysis. We believe our observations have benefit for others in the Computer Science Education community, especially those considering adopting Python as a first language. The context of our observations is important. CS1 is breadth first course taken by both majors and non-majors. However, we do emphasize programming as described in detail in [5]. Students completing CS1 and continuing in our program typically move into one of two subsequent courses, depending on whether they took CS1 in fall or spring. Fall CS1 students move into a traditional CS2 with emphasis on data structures. The primary ___________________________________________ *

Copyright © 2005 by the Consortium for Computing Sciences in Colleges. Permission to copy without fee all or part of this material is granted provided that the copies are not made or distributed for direct commercial advantage, the CCSC copyright notice and the title of the publication and its date appear, and notice is given that copying is by permission of the Consortium for Computing Sciences in Colleges. To copy otherwise, or to republish, requires a fee and/or specific permission. 7

JCSC 20, 6 (June 2005) language in CS2 is Java. Spring CS1 students move into a computer organization and architecture course. In that course we choose to focus on the MIPS architecture, as presented in Patterson and Hennessey [4]. Later course offerings are traditional artifact based courses, including operating systems, database, compilers, software engineering, and programming languages. We will begin teaching a software development course, largely as described in the LACS model curriculum [1] in the 2005-2006 year. We found cause to reflect on our early use of Python particularly when thinking about CS2, and organization. We still found echoes of Python in CS1 when discussing later courses. GOALS RELATED TO PRGRAMMING IN CS1 We can state our goals for CS1, restricted to what we want students to gain from their programming experience in that course, simply. Students should: 1. Have productive fun in CS1. 2. Learn basic programming concepts and constructs. 3. Get a significant introduction to object oriented programming. Our first goal is important because in our school many majors are found by students taking CS1 for general education credit becoming interested in computing. In broad terms Python fits well with our goals. It: has features that allow students to have more than the usual amount of fun in CS1; includes enough basic programming constructs; supports object orientation without requiring an objects first approach. Others have recognized that Python improves productivity by delivering a positive experience [2] . We agree, and can express this in terms of our goals. We can also provide caveats. PYTHON AND THE STUDENT EXPERIENCE Our students report, and we observe, that they enjoy learning Python in CS1 because Python allows a beginning student to get going quickly on interesting projects. The syntax is generally easy, the environment friendly, and there are built in features that make the language highly expressive even for novice programmers. For example, dictionaries and built-in string functionality help beginning students write programs that deal with more interesting data at lower cost than is found in many early programming experiences. Packages such as VPython [11] or Zelle’s graphics module [6] allow beginning students to write programs with graphical components, even in a breadth first course. Python is a language that students perceive as mainstream rather than a “useless language.” Because Python is freely available on multiple platforms there is no monetary or environmental burden placed on the student. The results of using Python as a first language are almost uniformly positive in terms of student experience. We can be more specific. Python has an active community of open source developers who provide both lively discussions and useful modules. Students learn that they are part of a wider computing community. This lesson enhances continued student enjoyment of and success in the field and the benefit pertains in all subsequent courses. Python is a scripting language. CGI scripting allows students to program to a web interface. CGI scripting also gives students early exposure to topics that appear later: 8

CCSC:Mid-South Conference programming with a web interface and event driven programming. Early exposure greatly enhances later experiences. This benefit pertains most directly in our database course and in our planned software development course. Python provides an interactive shell, which encourages students to experiment on the fly. Students learn the fundamental skill of using programming tools to investigate how things work. When considering the student experience and the choice of Python in CS1 we really do not find significant downstream curricular issues. Python in CS1 does a great job helping us meet our first goal or providing students an enjoyable, productive CS1. PYTHON AND BASIC PROGRAMMING CONCEPTS AND CONSTRUCTS Using Python for teaching basic programming offers both benefits and issues. Benefits of Python in Teaching Basic Programming Concepts and Constructs The bulk of Python syntax is mainstream. Operators, if statements, while loops and so on learned in Python are useful in subsequent languages. One significant superficial variation in Python is the use of indentation for grouping statements. However, we observe that students adapt readily to the use of grouping symbols in CS2. Python has excellent string processing and regular expression tools. Students begin programming with strings early on, increasing the breadth of problems we can assign. Students learn basic string handling functionality in a good environment; strings aren’t hard. Regular expressions can be introduced as a useful tool and an important theoretic construct. Students can leave CS1 with some experience in simple parsing. Parsing issues can be a hold up in many projects in later courses. This early experience with strings and regular expressions has a broadly applicable benefit downstream. Python has good support for fundamental structures. Python lists are syntactically similar to arrays in most languages, but fully heterogeneous. Python for loops provide a clear mechanism for iteration over lists. Python provides a built-in dictionary type. CS2 students benefit from early familiarity with both indexed and associative structures; they can approach the details of hash tables as simply the details behind a useful tool. Python supports important concepts. We do not prefer an objects first approach, but do teach modularization. Python supports functions and modules. A Python module is a (source) file of functions. The development community extends Python using modules. This has several benefits for our students. Students can examine modules of source code provided by serious developers. Students leave CS1 with concepts of multi-file programming and extending a language by modules. Students immediately begin organizing their own solutions in a modular way. This broadly applicable concept cannot be introduced too soon. Finally, Python has a built-in mechanism for documentation, documentation strings, which is easy to use. Exposing students to a language with built-in documentation support helps demonstrate the importance of documentation.

9

JCSC 20, 6 (June 2005) Issues Raised by using Python to Teach Basic Concepts and Constructs Any programming language not designed for classroom use presents pedagogic issues. Our task is to point out the issues we have observed while using Python, and tell the reader what we do about addressing these issues. The broad general issues of many languages appear with Python. Like any other “industrial strength” language there is more to Python than we care to teach. We must choose an effective subset of the language to cover. In the past students have sometimes raised issue with our choice of text. Until 2004 there has been no CS1 text using Python as the exemplary language. In fall 2004 we began using Zelle’s text [6], and were pleased with it on a first go-round. Finally, Python evolves quickly, and changes from release to release can be significant. Since students typically download the latest version of Python, and Python releases do not follow the academic calendar, faculty have to be aware of new releases and their features. Laboratory environments have to be kept reasonably current. For instance, as of Python 2.2, the division operator / has a companion, floor division (//). 7/2 and 2//2 both yield 3, while 7.0/2 yields 3.5 and 7.0//2 yields 3. In Python 3.0 the semantics of / will change, and 7/2 will yield 3.5 [9]. Python development is organized enough, however, to have a defined strategy for changes in the language [8]. More specific issues exist with using Python to teach basic programming. Foremost, Python’s dynamic typing leaves students lacking practical exposure to many concepts associated with type. Python variables are associated with an identifier. The variable is created when the identifier appears on the left side of an assignment statement. The identifier is just a label referring to an object. The identifier can be made to refer to any other object by placing the identifier on the left of another assignment statement. Thus, Python declaration is done only at the time of first use and lacks explicit type information. Declarations lack explicit type because all type information is associated with the object referenced, not the identifier that references the object. Students do not have any trouble learning to create and use variables in Python, but they do not learn much about type. (There is one pitfall for students; misspelling a variable name on the left side of an assignment simply creates a new variable with the variant identifier. Thus, x=1 on line 23 creates x, while X=3 10 lines later creates X. For novice programmers the difference between x and X is difficult to spot, and the language does nothing to help.) Introducing students to Java in CS2 allows us to discuss type more completely with students. We do make more of a point of explaining type and distinguishing declaration from definition in CS2 than might be otherwise expected. From the perspective of teaching beginning students, Python offers several other “concepts and constructs” quirks. Python does not adequately represent compilation or pointers, and its approach to parameter passing is rather odd. Python code is interpreted. Behind the scenes byte code is generated and executed on a virtual machine. From a student’s perspective there is no compilation phase. Yet our preferred text in organization refers to compilation as matter of course. Students who come to organization from CS2 (and Java) have less difficulty, having seen a compilation phase, than those who come directly from CS1. Compilation alone might be adequately addressed by the CS2 course. 10

CCSC:Mid-South Conference Python (as Java) has no need for explicit pointers. Python creates a unique id for each variable, which is implemented as an address. The built-in function id() can be used to obtain this value. When variable x is assigned a new value, x gets a new id. This introduces the concept of addressing, but it is not equivalent to students using pointers. Python uses “pass by assignment” semantics in function calls. Roughly speaking this means that the formal parameter of the function is a reference to the actual parameter up until the formal parameter is assigned a new value. At that point the formal parameter no longer references the actual parameter, and their respective values need no longer agree. (This can look like value semantics.) These semantics are not unique [10]. These semantics are consistent within Python. However, it is difficult to address the traditional distinction between value, reference and address parameters in this context. Having moved to “more modern” languages in CS1 and CS2 we find we face several “concept and construct” issues. We conclude that the students need a better understanding of compilation following CS1, an understanding of pointers following CS1 and CS2, and a better model to discuss parameter passing. Since our organization text refers to C and compilation we have chosen to address these issues directly in the organization course. We will provide a brief, focused introduction to C by way of background at the outset of the organization course beginning spring 2005. OBJECT ORIENTATION IN PYTHON In CS1 we seek only to introduce object orientation. Using Python students begin using objects almost immediately. As with Python dictionaries, we believe early use facilitates subsequent student understanding of both concept and mechanism. After students have written several useful programs without writing their own classes we can have them develop meaningful classes in preparation for Java in CS2. However, Python’s flavor of object orientation introduces some issues. Issues Raised by using Python to teach Object Orientation Python does not support data hiding well. In Python, “data hiding is a convention, not a syntactical constraint” [3]. In other words, there really is no such thing as a private data member. If one wants to teach object oriented design with strict data hiding from the outset then Python may be a poor choice. Rather than introduce the details of Python’s conventions for pseudo-private attributes, we require students to use getters and setters for attributes when building Python classes. Our students may not write perfectly idiomatic Python, but they will develop habits we want. In Python, instance variables (corresponding to Java instance fields) are defined in the __init__() function (constructor.) Variables defined in the class definition are shared by all instances (Java static fields.) Python instances can override class variables using the same identifier. For example, given class C, initially each instance may share class field F. However, it is perfectly legal for C object Oj to assign a unique value to F, so that Oj.F g C.F, while for all kgj, Ok.F==C.F. Because shared fields may not be important in CS1 this could be ignored. However, these semantics are consistent with the following legal behavior. Objects Oj and Ok are instances of class C. Each has a single 11

JCSC 20, 6 (June 2005) instance field F1. The following is perfectly legal: Oj.F2 = 1. Now Oj has instance field F2, but Ok does not have such a field. While not unique to Python and sometimes useful, these semantics make could make it difficult to teach or learn the basic idea of using a class to model a set of objects with common features. This is another aspect of Python’s object orientation that we simply avoid. We prefer the model of object orientation in Java. We ignore or discourage use of Python features that are inconsistent with the Java model. However, Python allows us to impart some basic, useful object oriented concepts, which benefit students entering CS2. CONCLUSIONS It is always difficult to judge the effects of curricular change in any objective way. Our program is too small for meaningful statistical analysis. We can observe that there is little difference in the percentage of students going from CS1 to the next available computing course when we compare a period of time just before our switch to Python to a period of time after the change. (See Table 1.) Further, our graduates in Computer Science have taken the ETS exam for a number of years, and we cannot recognize any significant change in scores on the ETS exam following the introduction of Python. Table 1. CS1 Enrollment Next Course Enrollment R e t e n t i o n (Next/CS1)

S98 – F99 (pre Python) 86 50

S03-F04 (post Python) 83 45

58%

54%

Qualitatively, while we recognize some issues raised by starting students in Python, we do not believe they are worse than the set of issues we would face given any other choice for a first language. None of the issues we have recognized is particularly difficult to handle. Most issues are addressed naturally in CS2 or the Computer Organization course. The most important response is for faculty to be aware of what the CS1 experience with Python does and does not provide. On the other hand, some of the benefits of Python, especially the less tangible benefits discussed above as part of the student experience, persist throughout the curriculum. Our program remains committed to using Python in CS1. For us it seems a good fit; we enjoy seeing the students have fun. The course receives good marks on student evaluations and on senior exit interviews. We offer this review to help guide others in their decision making if they are considering moving to Python, or to help them recognize pitfalls if they have recently adopted Python.

REFERENCES [1] Liberal Arts Computer Science Consortium, A 2004 Model for a Liberal Arts Degree in Computer Science, February 27, 2004 draft, available at http://www.cs.hope.edu/lacs. (Visited September 6, 2004.) 12

CCSC:Mid-South Conference [2] Hendrix, Amy, Snake Charmer, NetWorker, 8, 1 (March 2004), 26-30. [3] Lutz, M., Ascher, D., Learning Python, second edition. O’Reilly, 2003 [4] Patterson, A., Hennessy, J., Computer Organization and Design: The Hardware / Software Interface, second edition. Moran Kaufmann, San Francisco, CA, 1998. [5] Shannon, C., Another breadth-first approach to CS I using Python. In Proceedings of the 34th SIGCSE technical symposium on Computer science education (SIGCSE ’03) (Reno, Nevada, USA). ACM Press, New York, NY, 2003, 248-251. [6] Zelle, J. Python Programming: An Introduction to Computer Science. Franklin, Beedle & Associates, Wilsonville, OR, 2004. [7] Computing Curricula 2001 Computer Science Volume. Available at http://www.sigcse.org/cc2001/ (Visited September 6, 2004.) [8] http://www.Python.org/peps (Visited September 6, 2004). [9] http://www.Python.org/peps/pep-3000.html (Visited September 6, 2004). [10] http://www.ruycentral.com (Visited September 6, 2004). [11] http://www.vPython.org (Visited September 6, 2004).

13