Bits and Blocks Level 2: Logo to Python
In addition to whole class, small group and one-on-one discussions, lessons are delivered in a range of online formats to support independent study and differentiate instruction based on your needs.
Python in Your Browser
For this course, we will use a web-based development environment for our work with Python. This environment is called CodeSkulptor. It runs on recent versions of Chrome, Firefox and Safari browsers (sorry, it does not work with Internet Explorer). Python support in this environment is slightly different from standard support, and not all Python libraries have been implemented in CodeSkulptor. However, CodeSkulptor does supply all the support needed for the development of cool games as well as support for porting games developed in CodeSkulptor to more traditional Python development environments and libraries (like Pygame).
Logo and Python
Logo and Python are two of the computer programming languages taught at the Center for Talent Development. Since its inception in the 1960s, Logo has been used primarily as a learning tool for elementary school children. However, it has many powerful capabilities that make it suitable for use in advanced mathematics and computer science courses, and has been used for these purposes at high school, undergraduate and graduate levels.
Python is used daily to drive the Google search engine, YouTube and applications at NASA and the New York Stock Exchange. In the previous Bits and Blocks course, you built games using the predefined classes and simplified framework of the MicroWorlds development environment. In this course, you will learn to build classes from scratch as they develop their own game engine. This understanding of object-oriented programming will serve them in further Python development and can readily be applied to other object-oriented languages like Java and Objective-C.
On this page, I'm writing up comparisons between Logo and Python to help Logo programmers make the move to Python.
The learning objectives of the course are guided by the documents Computing Curricula 2001: Computer and Computer Science Curriculum 2008: An Interim Revision of CS 2001, from the Joint Task Force on Computing Curricula. The Computing Curricula volumes are developed jointly by the ACM and IEEE Computer Society on cycles of about 10 years. Work on the next volume, Computer Science 2013, began in 2010.
This page does not include anything about software development methodologies like agile or design patterns or refactoring or any of that stuff. That will come at another time on another page.
Before diving into the content, I want to be clear that the classroom activities will continue to revolve around student interest, as they did in the first Bits and Blocks course. Most of this content is taught in the context of project work because it's stuff kids need to know in order to build cool projects. Some content is also shared in short lessons, videos and online readings. Kids have a lot of fun in my classes. They also learn a lot and are proud of the projects they build.
Not all of the content below will be covered in the course. I always plan for more content than I can possibly include in a single course because I want to make sure everybody gets their fill. Not all kids will receive all of the same content
In other words, this is an explanation of the nutritional value of the class, not its flavor.
MicroWorlds and CodeSkulptor
Computers languages are used to translate human ideas into machine actions. Part of this translation is done by people. We have an idea of something we want the computer to do, and we write a program to tell the computer how and when to do it.
The other part of the translation is done by the computer. The computer takes the program we've written and tries to translate it into machine code that it knows how to execute. Both of these tasks are aided by programming environments.
MicroWorlds and CodeSkulptor are programming environments used in Bits and Blocks Level 2. MicroWorlds was made to support Logo programming. CodeSkulptor supports programming in Python. They both give programmers a window that shows what happens when the program is run. In MicroWorlds, this is called the Main Window. There is no graphics display area built into CodeSkulptor. Instead, programmers must create and show windows themselves.
In MicroWorlds, programmers can place backgrounds, turtles, text boxes and other objects on the Main Window by using the tool bar. CodeSkulptor does not provide this facility. However, both MicroWorlds and CodeSkulptor allow programmers to create objects automatically.
Both MicroWorlds and CodeSkulptor have areas where programmers can write their programs. In MicroWorlds, programs are written in Procedure tabs for the project and for individual turtles. In CodeSkulptor, programs are written in the Editor.
In CodeSkulptor, the work of the MicroWorlds Command Center is shared by the Editor and the Console area. As mentioned above, the Editor is the area where you write programs. In this way, it is like the Procedures tabs. However, you can also write instructions in the Editor and run them directly the way you do in the MicroWorlds Command Center.
However, MicroWorlds uses the Command Center for message to and from the environment. For example, if you send MicroWorlds a show command from the Command Center, a word or list is written to the Command Center. Error messages are also written to the Command Center. In CodeSkulptor, message to the environment are written in the Editor, while message from the environment are written to the Console area.
Objects and Classes
In computer programming, an object is something that stores information and knows how to do certain things. A class of objects is a group of objects that all store the same kind of information and know how to do the same kinds of things. Whenever we create a new object of a certain class, we say that we have created an instance of that class.
A turtle in Logo might be considered an object. We can ask any turtle for information about itself, or change that information. For example, we can use procedures like
Most modern versions of Logo allow programmers to create multiple turtles. Each turtle may have a different heading and position, but each turtle keeps track of its heading and position, and each turtle knows how to move forward and backward and turn right or left. Every time you add a new turtle to your main window in MicroWorlds (using the tool bar or the newturtle procedure), you are creating a new instance of the turtle class.
A Logo procedure that has already been written for you (like forward, or pos) is called a primitive. A class that has already been written for you is a predefined class. Turtles in Logo are something like a predefined class.
In addition to turtles, MicroWorlds provides text boxes, buttons and other things that you can add to your main window with your mouse or using the commands newtext, newbutton, newcheckbox, newdropdown, newlistbox, newpage, newroundbuttonset, or newslider. Whenever you create one of these objects, it is automatically given a name such as "t1 for turtles, "text1 for text boxes and so on, and you can give these objects a name of your choice. These object names allow you to give commands or get information from particular objects.
You can write your Python code in a functional way, like you do with Logo, or you can write classes and subclasses. A subclass is a class that inherits data fields and behavior from another class. This allows procedure in Python to be associated with a particular object or a particular class.
For example, suppose you had a Python class named Turtle that had data fields for heading, position, and size. This Turtle class also includes procedures like forward and right. Let's say we also have a method called
Now suppose we want some of our turtles to be snapping turtles. Snapping turtles can't fit their whole bodies inside their shells, so they snap at their enemies instead. In Python, we could create a subclass called SnappingTurtle. As a subclass of Turtle, any instance of SnappingTurtle would inherit all the data fields of a Turtle (heading, position and size) and all the behaviors of a Turtle (like forward and right).
We could also overwrite the Python class's
Now, when a turtle is under attack, we don't need to think about what kind of turtle it is. We can just invoke the
In MicroWorlds, we can do something like subclassing by using private procedures in a turtle's backpack or using turtle variables to decide what kind of turtle we're talking to, but as we'll see, this kind of subclassing is quite limited compared to that available in a fully object-oriented programming language like Python.
Another level of organization in Python is the module. Modules can contain classes and their functions or just a bunch of functions that are not associated with any particular class. The Pygame modules contain a great set of classes for game developers.
Procedures and Functions
Topics for this content area include the following:
Order of Execution
Topics for this content area include the following:
Both Logo and Python have sophisticated list processing capabilities. Here are some examples.
Both Logo and Python are languages used to develop source code. Both are typically interpreted languages. You can execute instructions "on the fly" in the MicroWorlds Command Center or in the CodeSkulptor Editor.
CodeSkulptor does some syntax checking before it tries to execute a program. Some versions of Logo (like Berkeley Logo) provide a trace tool to help programmers find defects.
Both languages allow programmers to add comments to code.
Both languages provide extensive documentation on existing primitive procedures/classes and methods
Data in MicroWorlds Logo can be a word or a list. Python has more built-in types of data, like: byte, short, int, long, float, double, boolean, or char.
Variables in MicroWorlds Logo can be project variables, turtle variables, global variables, local variables or inputs. Variables in Python can be class variables, instance variables, local variables or parameters.
In Python, new objects are created with constructors. In MicroWorlds Logo, new objects are using special purpose procedures like newturtle, newtext and so on. To reference a particular object, we use
In MicroWorlds Logo, we assign values to project variables and turtle variables with setName and assign values to
Strings in Python have quotes before and after the elements of the string. In MicroWorlds, a word begins with a single quote and ends when a space is encountered. Concatenation of Strings is done with a + in Python. Concatenation of words is done with the
In Python you can represent collections of things as lists, tuples and dictionaries. Logo has lists. You can reference elements of a list in Python using an index in brackets. You can reference an element of a Logo list with primitive procedures
Both languages have ways of distinguishing between constants, variables, and procedure/method names.
About the Center for Talent Development
Center for Talent Development (CTD), housed at Northwestern University's School of Education and Social Policy, is an accredited learning center and research facility that identifies, educates and supports gifted students and their families and serves as a leader in gifted education. Learn more about the Center for Talent Development.