python as a teaching language

Upload: zubayr-moro

Post on 07-Apr-2018

226 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/6/2019 Python as a Teaching Language

    1/9

    Python as a Teaching Language

    Purpose of this document

    Introduction and intended audienceThis paper is written to help A-Level centres assess the suitability of Python as a teachinglanguage. It is specifically written for centres that follow the AQA New (2009)specification for Computing A-Level. Python is one of several possible languages forthis specification, each of which has advantages and drawbacks. This paper aims to spellout the arguments for and against the adoption of Python as a first language, so thatcentres can make an informed decision, plan for implementation if appropriate, anticipateand avoid difficulties in deployment.

    Background

    The paper is based on a single years experience in moving from a Visual Basicenvironment to Python in an English Comprehensive School. Overall we consider thetransition to have been successful and our results at AS back up this view obviouslyonly time will tell whether this preliminary judgement is sound.

    Quick overview

    The LanguagePython is a high level, dynamic, general purpose programming language. It has becomepopular as a scripting language partly due to the ease with which concepts can beexpressed the language is often affectionately described as an executable pseudo-code 1.

    In addition to the elegant core of the language, it is straightforward to create extensions;as a res ult open source or free libraries can be found and freely used for almost anypurpose 2. There is a large and enthusiastic support community on-line, together withextensive support resources and example materials. The language is owned by a softwa refoundation and distributed under an open source licence that makes it free to use 3.Students find that it is simple to install the language on home machines allowingteachers to set practical homework tasks and thus maximise the overall time spentpracticing the craft.

    Python looks different from other programming languages because of the way in which ituses whitespace. Python uses indentation to indicate blocks of code, blocks that in other

    languages are marked with begin and end statements or braces. Although newstudents find this easy and intuitive, experienced programmers sometimes find this a littleawkward at first. The adjustment, however, is usually rapid.

    1 Jython - http://hugunin.net/story_of_jython.html 2 Popular Python modules - http://www.catswhocode.com/blog/python-50-modules-for-all-needs3 Main Python Website - http://www.python.org/

    http://hugunin.net/story_of_jython.htmlhttp://hugunin.net/story_of_jython.html
  • 8/6/2019 Python as a Teaching Language

    2/9

    Python names and commands are case sensitive and the language discriminates betweenequality (==) and assignment (=). These two facts immediately generate a whole slew of novice errors, but the latter avoids, or rather makes manifest, the confusion betweenassignment and comparison in a similar way to Pascal.

    Deployment at SchoolImplementations of the language are available for a very wide range of platforms,including Unix, Macintosh, web servers and mobile phones.

    There are a bewildering variety of implementations 4 possible for the standard schoolWindows XP environment, some of these, although initially attractive turn out to bepoorly documented and hard to deploy. The standard implementation of Python withthe IDLE editing environment available from python.org, or the Activestateimplementation are recommended if for no better reason than that they are welldocumented and straightforward for technicians to deploy.

    Industry and Higher EducationPython occupies the second rank of programming languages 5 (the first rank beingrestricted to C and Java) in terms of pop ularity and commercial adoption. Manyorganisations use it as their principal languag e6 and an increasing number of Universitiesuse Python in their Computer Science courses 7 .

    Positives Negatives

    Straighforward syntax, free of clutterallows students to focus on thefundamentals. Console code is simple,with no hidden setup structures and noneed to use complex objects for simpletasks. As a result teaching can concentrateon the fundamentals of programming ratherthan the quirks of a particular language.

    It is different from the prior generation of languages (C, Pascal, VB). Experiencedteachers or programmers making thetransition from such languages will haveto adjust some of their basic concepts, forexample: the absence of explicit datatyping and the fact that Python names arelabels for objects rather than traditionalvariables requires a change in teachingapproach over traditional languages.

    4 Python WIKI IDEs - http://wiki.python.org/moin/IntegratedDevelopmentEnvironments5 Language popularity charts - http://langpop.com/ 16/7/096 Commercial adoption - http://www.python.org/about/quotes/ 7 York University - http://www.cs.york.ac.uk/admit/Modules/ipp.html

    http://langpop.com/http://langpop.com/
  • 8/6/2019 Python as a Teaching Language

    3/9

    Positives Negatives

    Implementations and resources are OpenSource, free and can be used at home on awide variety of platforms including Unix,web servers, Macintosh and some cellphones. On a Windows environment thewhole language and supporting programscan be run from a memory stick withoutany prior installation.

    Although integrated environments existfor Python, they are not as well developedas the Microsoft or Delphi IDEs. Oneconsequence is that Pythons debuggingand error reporting compare unfavourablywith other languages. Names andcommands are case sensitive. Whitespaceerrors are possible, though rare.

    Strong, enthusiastic and very active supportcommunity which has posted a vast rangeof examples and created comprehensive setof extensions and libraries.

    The transition from console programmingto GUI development requires the masteryof an additional library and there are nodrag-and-drop GUI editors at present forPython.

    Excellent study guides, documentation andother teaching resources available on theWeb for example Think Python, atranslation of the classic introductory textHow to think like a Computer Scientis tand available as a free .pdf for download 8 .For experienced programmers, Dive intoPython is a focused introduction to thelanguage, also freely available on-line. 9

    The fit with the Pascal based approach tothe AS curriculum is not perfect. SomePascal concepts, such as procedures andarrays, have only rather artificial Pythonequivalents. Examples in the AQAtextbooks will need to be re-cast to beunderstood by students.

    A growing body of anecdotal and moreformal research experience suggesting thatstudents find Python easier to understandthan comparable languages and bec omeindependently productive more quickly. 10

    Python encourages, but does not enforce,a readable coding style. The moreadventurous and able, exploring aspects of the language such as lambda functions,can create masterpieces of obscurity. Aswith any language, good practice can andshould be taught from the outset.

    By way of summary, Python is free, straightforward and well supported. It allows theteacher to focus on the fundamentals of programming and the structures of algorithms.Using Python in the current Pascal based AS syllabus does require that some aspects of

    the AS course are sensitively adapted. This is not too difficult, the languages are verysimilar in many ways, Python shares many of the structures that make Pascal an excellentteaching language. Python is not just a teaching language, however, it has features

    8 Think Python - http://www.greenteapress.com/thinkpython/thinkpython.html9 Dive into Python, Mark Pilgrim - http://diveintopython.org/ 10 Teaching Scientific Programming using Python, Mark Williams 2002http://pentangle.net/python/report/publicreport.html

  • 8/6/2019 Python as a Teaching Language

    4/9

    which go well beyond Pascal in sophistication, incorporating modern language featuressuch as regular expressions - furthermore, because it plays nice with C, a very widevariety of third-party, Open Source extension modules are available to the Pythonprogrammer.

    Specific issues for consideration Object OrientationPython is an object oriented language. Everything in Python is an object, creating newclasses and instantiating objects are straightforward processes.

    There is considerable debate among those teaching A-level Computing as to the best wayand right time to introduce object orientation. It is possible to teach an entire A-levelcourse using Python without using objects or classes at all. Alternatively the conceptscan be introduced in the first lesson.

    Python does not require that the programmer master object techniques in order to be

    productive - by way of example, the AS level sample program makes no explicit use of objects. Set against this, students who are not introduced to object techniques early arelikely to find most on-line Python tutorials and code examples hard to understand.

    GraphicsThe basic implementation of Python does not include a drag and drop GUI builder andrequires the use (and understanding) of additional modules to create graphic objects oruser interfaces. On the plus side, these modules are easily obtained. The most commonlyused and deployed graphics module is the TKinter library which comes as standard withmost implementations. Other options are the WX library and GTK+.

    None of these modules are particularly straightforward to use and most require someunderstanding of object orientation to write successful programs with graphics. Howeverthis is not essential in order to create a simple GUI, the EasyGUI module 11 allows a verystraightforward approach to GUI programming which dispenses with the requirement tomaster the event-driven paradigm or object orientation. The right approach to thedevelopment of applications can therefore be tailored to the student.

    There is a trade-off however. If the main task is to create a Windows only GUI program,then Visual Basic or Delphi, with their drag and drop GUI builders, have an advantage.The ease with which complex GUI forms can be created does come at a price, thepresence, although often hidden, in the program of large amounts of inscrutable machinegenerated code. Such automatic code can make teaching difficult, the teacher has an

    unwelcome choice: either try to explain it to pupils who lack the conceptual grounding tounderstand, or advise the students to ignore it, whilst trying to give clear guidance as toexactly what should be ignored and why.

    There is more to programming than developing Windows GUIs, extending student work into more challenging application domains is something that the current syllabus strongly

    11 EasyGUI Home - http://easygui.sourceforge.net/

  • 8/6/2019 Python as a Teaching Language

    5/9

    encourages. Here Python has a clear advantage over both VB and Delphi, since there is avast range of open-source extensions and enormous scope for experimentation andgenuinely new projects for example the Pybluez 12 library provides a simple interface toa computer or mobile phone Bluetooth stack.

    Versions, implementations and supportThe canonical implementations of Python are available from the website python.org. Attime of writing there are two, versions 2.6.2 and 3.1. Both of these versions are freedownloads and include the IDLE integrated development environment.

    Python 3.x represents a significant upgrade of the language wh ich is quite consciouslynot backwards compatible with earlier versions of the language 13 . This is obviously apotential problem. For A-level purposes however the changes between the two versionsare fairly straightforward: changing the way printing works; replacing raw_input withinput and dropping the comparison (use != instead). There are, of course, manymore significant changes but these are unlikely to affect novice coding. By way of example the author has edited the Python 2.x skeleton program issued for the 2009COMP1 exam to make it run under Python 3.1, the work was largely mechanical andtook less than ten minutes.

    Other noteworthy implementations of Python are:

    The Activestate package which includes its own integrated developmentenvironment and a set of additional modules specifically for the Windowsenvironment.

    Portable Python, a lightweight implementation which can run from a USB stick Jython: an implementation of Python in Java, using the Java Virtual Machine

    IronPython, a Microsoft project that targets .NET and Silverlight.

    SupportThere is an active newsgroup, comp.lang.python on usenet

    There is also an extremely active mailing list, called Tutor 14 which is specifically forthose learning the language. Typically there will be upwards of 10 messages per day onthis list. The mailing list is perhaps the clearest example of why Python is recommendedfor novice programmers, it is an extremely respectful, resourceful and helpful supportenvironment.

    Moving to Python from Visual Basic An experienced Visual Basic Programmer may struggle initially with the unfamiliarlook of Python. As with the majority of modern languages, Python is case sensitive,

    12 Pybluez library - http://code.google.com/p/pybluez/ 13 Comparison between 2 and 3 - http://docs.python.org/3.0/whatsnew/3.0.html14 Tutor information page: http://mail.python.org/mailman/listinfo/tutor

  • 8/6/2019 Python as a Teaching Language

    6/9

    something that will doubtless cause irritation if VB has been the language of choice. Afurther frustration is that the Integrated Development and Debugging environment is lessmature than Visual Studio.

    Set against this, Python has an interactive interpreter which means that simple commandscan be tested immediately, without a requirement to create, save, compile and run a file.

    When creating a program in Python there is no need to interface with a complex set of object structures and no requirement to generate a large amount of inscrutable, if hidden,supporting code to develop a simple application.

    Python is in many ways a more sophisticated language than Basic, with built-in supportfor exotic data structures and methods such as regular expressions. The language feelsmuch richer, with a much wider variety of support available on-line. There are moreways to approach problems in Python, more sense of exploration and discovery. Thelanguage benefits from being part of the University-driven hive of activity around Unixplatforms and Open-Source software.

    There are no arrays in Python. Alternatively there are four different types of array inPython and a further type from an external module. These four types, particular ly Lists,can simulate multi-dimensional arrays but the process is clumsy and requires care 15 .

    The way in which Python uses whitespace is appealing, but it does require discipline tomanage properly. A Python purist would say that tabs should not be used for indentation,four spaces is the recommended method. Using tab is a difficult habit to break. Mixingtabs and spaces can cause syntax errors. Most modern editors avoid any problems byautomatically replacing tabs with a set number of spaces.

    There is much to admire in the language, for example the way in which Python handlesglobal variables, requiring that they are explicitly identified as such within functions, isparticularly elegant and effective.

    The main issue for those moving from Visual Basic is likely to be the difficulty in writingWindows graphic user interface driven applications. With Visual Basic these are the firstand often the only kind of application that ever gets written. Python has no built-in GUIbuilder, the student must master a GUI toolkit in order to create such an interface.

    Moving to Python from Pascal or Delphi The points made in the previous section apply equally to those moving from a Delphienvironment.

    Since the AQA specification and supporting materials are very heavily weighted towardPascal or Delphi, a move to Python will require care in adapting some of the existingteaching material to a new language.

    Although a version of Delphi is available from Embarcadero without charge, it is not atrivial matter to install on a Windows machine. In contrast the Python implementations

    15 http://www.python.org/doc/faq/programming/#how-do-i-create-a-multidimensional-list

  • 8/6/2019 Python as a Teaching Language

    7/9

    represent the complete product and can, if required, be installed on a portable USBmemory device.

    Python does remove the requirement to declare constants, variables and functions in aspecific order. This allows related components to be grouped together in the programbody.

    The use of global variables is discouraged in Python, although they are available if required (and rather sensibly implemented). Making the move from Pascal to Python is aprocess of discovering alternative, safer and clearer ways to accomplish what isconventionally achieved using globals in Pascal.

    Four concluding quotations The paper by Jeffrey Elkner, from which the following extract is taken, describes anAmerican High Schools experience in moving first from Pascal to C++ and subsequentlyto Python. It is worth reading in full. It is a thoughtful exploration of the teaching andlearning issues that make the subject of programming so difficult to teach well.

    Another example of how Python aids in the teaching and learning of programming is in its syntax for functions. Of all the things that I learned byusing Python this year, the way in which the right tool could help inexplaining functions was the most exciting. My students have always had agreat deal of difficulty understanding functions. The main problem centersaround the difference between a function definition and a function call, and the related distinction between a parameter and an argument. Python comesto the rescue with syntax that is nothing short of beautiful. Functiondefinitions begin with the key word def , so I simply tell my students, "when

    you define a function, begin with def , followed by the name of the functionthat you are defining, when you call a function, simply call (type) out itsname." Parameters go with definitions, arguments go with calls. There areno return types or parameter types or reference and value parameters to get in the way, so I was able to teach functions this year in less then half thetime that it u sually took me, with what appears to be better comprehension. 16

    The second quote is the conclusion of a detailed paper written by Michael Williams atOxford University. The paper documents an extensive consultation exercise withstudents and can be explored in detail on-line. He concludes:

    I believe the trial has shown conclusively that it is both possible and desirable to

    use Python as the principal teaching language: it is Free (as in both cost and source code).

    16 Into the Classroom: Preliminary Thoughts on Python as a High School Programming Language, Jeffrey Elknerhttp://www.python.org/workshops/2000-01/proceedings/papers/elkner/pyYHS.html

  • 8/6/2019 Python as a Teaching Language

    8/9

    it is trivial to install on a Windows PC allowing students to take their interest further. For many the hurdle of installing a Pascal or C compiler ona Windows machine is either too expensive or too complicated;

    it is a flexible tool that allows both the teaching of traditional procedural programming and modern OOP; It can be used to teach a large number of

    transferable skills; it is a real-world programming language that can be and is used inacademia and the commercial world;

    it appears to be quicker to learn and, in combination with its many libraries,this offers the possibility of more rapid student development allowing thecourse to be made more challenging and varied;

    and most importantly, its clean syntax offers increased understanding and enjoyment for students;

    Python should be used as the first year teaching language. If used it will be possibleto teach stu dents more programming and less of the peculiarities of a particular

    language. 17

    The third quote is from Roger Davies, a Computing Teacher at Queen Elizabeth Schoolin Cumbria. He has been teaching the new AQA syllabus using Python:

    The main advantage for me is the clarity of syntax. This is a huge issue withbeginner programming, particularly as many pupils cant writegrammatically correct English. Perpetual syntax errors are soul destroying

    Python helps maintain enthusiasm because you get programs working fairly quickly. Much easier therefore to build up pupil knowledge.

    The final quote is from Steve Holden, Chairman of the Python Software Foundation,whose help in preparing this paper is much appreciated.

    The Python Software Foundation, the body charged with the promotionand development of the Python language, is keen to promote Pythons use asa teaching language. This is not because of partisan concerns but becauseof a belief in Pythons fitness for the purpose.

    Unusually, Python was designed to be easy to write. This acknowledgesthat programming languages are an important means of communicatingalgorithms. Early computer science education benefits from a focus onalgorithmic design, and sample Python code is valuable in educationalcontexts in ways that other code might not be. The dual nature of thelanguage (with good features for both procedural and object-oriented

    programming) makes it adaptable to a variety of pedagogical approaches.

    17 Teaching scientific programming using Python, Michael Willliams, Oxford Universityhttp://pentangle.net/python/report/publicreport.html

  • 8/6/2019 Python as a Teaching Language

    9/9

    This adaptability, coupled with the existing support for a large rangeof application domains (from numerical computation and bioinformatics tonetworking), means that Python is a great learning tool that will stand students in good stead as their programming skill increases.

    Further Reading and Resources Languages and Tools

    Principal Python Website http://www.python.org

    ActiveState Python http://www.activestate.com/activepython/

    Textbooks and teaching resources

    Think Python http://www.greenteapress.com/thinkpython/thinkpython.html

    Dive into Python http://www.diveintopython.org/toc/index.html

    Libraries and other add-ons

    PyGame http://www.pygame.org/news.html

    EasyGui http://easygui.sourceforge.net/

    Python SQL http://oss.itsystementwicklung.de/trac/pysqlite

    Support communities

    Python Newsgroup http://groups.google.com/group/comp.lang.python/topics

    Tutor Mailing List http://mail.python.org/mailman/listinfo/tutor

    Research Papers

    Teaching using Python http://pentangle.net/python/report/publicreport.html

    Python in the Classroomhttp://www.python.org/workshops/2000-01/proceedings/papers/elkner/pyYHS.html

    Graham Macleod 22 nd July 2009 www.ictlesson.com

    http://www.ictlesson.com/http://www.ictlesson.com/http://www.ictlesson.com/