Logistics
- Roll
- Any questions/wonderings concerning the extra credit project?
- Any general questions/comments/wonderings?
Sample Exam Review
This class introduces you to programming but doesn't teach it like we would teach it to a CS major. However, we (I) do want to know how well you develop some basic understandings in comparison to them. Typically, CS majors will have seen questions like the ones on the exam you took last time. And you haven't really. Now you have and you will again. The goal today is to help you see/understand the issues being examined by the exam. This discussion will be your major learning activity. Please keep in mind that very similar items will be on the final exam and will be part of your grade.
[ Return exams to students; develop & discuss solutions to each problem. ] Questions/wonderings about any other exam items? [ Any other questions/wonderings?
Programming Basics
We have seen and done some programming in one language and are about to look at another. Let's consider for a moment what is similar and different about programming languages. They all share the same basic capabilities:
- Data and actions
All programming languages have actions. In many languages the only actions are get input, manipulate data and use or store the result, and produce output. Scratch has these capabilities but it also has many other actions due to its graphical context.
- Organizing the actions
Programming languages allow their actions to be organized in the various ways, identified and discussed below. This is true of all modern programming languages, including Scratch (and Logo). We are all familiar with these organizational approaches but we tend not to consider them explicitly.
- Sequence
Sequence involves placing the actions in an appropriate order for accomplishing the desired task. It is important to remember that each action occurs in sequence (one after the other) and only at that time. Actions are not rules or relations that persist over time. They just occur the one time (unless they are explicitly repeated, see below). The result of the action does persist—until some other action changes it.
- Selection
Selection is the capability of choosing between actions or between doing or not doing an action. It almost always uses an if statement though some languages have other statements that are used when multiple choices are available.
The availability of a selection statement as a control mechanism can substantially increase the complexity of a program. Now the programmer must be concerned not only with identifying the action(s) to be selected but also what action(s) comes before and after the selection. Additionally, The selection activity can include another selection activity which can include another selection activity, and so on.
- Repetition
Repetition is the capability of having actions occur over and over again. The repetition occurs a certain number of times or until some particular event happens or program state occurs. As with selection, the programer must identify actions to be repeated and actions that come before and after the repetition.
Also, as with selection, the repeated actions can include selection statements and other repetition statements. Thus, the complexity of the programs automatically becomes more complex with repetition.
- Modularization
Modularization is essentially the building of new programming instructions or actions. It involves identifying a set of actions (probably including selection and repetition) that accomplish a particular task within the overall program activity. You can isolate those actions in a named module (often called a subroutine or function, or a block as in Scratch) that effectively identifies a new instruction. Then you use the new instruction name in place of wherever the set of actions need to occur.
Modularization actually helps simplify the program or reduce the complexity. Developing and using modules helps the programming think more abstractly about the problem. An example from everyday life is go to the store and pick up bread, milk, and candy. All the details about the task, e.g., which store, how to get there, where to fine the items in the store, paying the cashier, coming home, etc. can be ignored when thinking about the task.
Modularization also simplifies debugging programs and changing them when that needs to occur. Instead of looking at duplicated code and changing each instance of it, only the code in the module needs be changed.
Any questions, comments, wonderings?
- Sequence
Most programming languages are designed with some particular purpose or set of purposes in mind. They share the above basics but have differences that relate to their purpose. Scratch was meant to be easy to learn and use, particularly for kids. Other languages are meant for solving problems in general or perhaps in some particular domain. Ease of learning and use is typically not important, per se, in most programming languages (though they are considerations).
One thing that seems to make Scratch relatively easy to program in (as compared to some other languages) is that you mostly have all the instructions right in from of you. All you have to do is look for the right one, choose it, put in in the proper place, and make sure of any data values in it. With other programming languages that is not so. You have to know or look up the instructions. And, you have to type the instructions which means there is a possibility of typing errors.
NetLogo Information
NetLogo is a variant of the Logo programming language. Logo was designed to teach programming to children. The main context for Logo programming was drawing, much as we have done in Scratch. Originally, Logo programs guided a physical robot that was place on paper on the floor. The robot could move around and could raise and lower a pen that attached to it. Logo and it use was the brain child of Seymour Papert who worked at MIT. (Disciples of his, produced Scratch.)
The focus in Logo programming was the creation of new instructions (referred to as procedures) that could be combined to accomplish larger tasks. The Logo language had basic actions similar to sprites in Scratch but it was cumbersome to just sequence the actions without putting them in a block and naming the block.
Early educational research with Logo programming indicated that essentially all students could learn to program and that being good at other school work was not required for being good at programming. Indeed, often students who performed less well in school (or came from low socioeconomic situations) often performed quite well at programming. Papert's main idea was to have students learn by doing instead of learning "about" stuff.
The NetLogo Environment
(You are expected to have read Sante Fe Institute's core concepts document (a PDF) and to have downloaded and installed NetLogo on your computer from the NetLogo site at Northwestern. Any questions, comments, or wonderings about that material? Any trouble installing NetLogo? )
NetLogo is a programming environment much like the Scratch programming environment. It allows you to write and test programs and to save them to run or revise at a later time. Running a Logo program in this environment requires a particular set of steps.
- [ Start NetLogo ... ]
This is an empty program. You can create a new program or load a previously written program. (We are going to load a program and discuss the interface with a loaded program.) Questions? Comments? Wonderings?
- Models Library (in the File menu)—load Termites (from Biology collection)
- Interface window/tab
- controls—Add icon and control selection combo box
- running the program (normally requires setUp and go buttons (or similar functionality defined by programming)
- speed setting
- Questions? Comments? Wonderings?
- Code window/tab
- note code for setUp and go "procedures"
- Questions? Comments? Wonderings?
- Run the program
- click on the setup button, then click the go button
Questions? Comments? Wonderings?
- examine the program in motion
- watch the program run for a bit Questions? Comments? Wonderings?
- slow down the action Questions? Comments? Wonderings?
- speed the action up (a lot)
- examine the code
- Are you able to understand the code for "setup"
- Are you able to understand the code for "go"
- Questions? Comments? Wonderings?
- look back at what the program has done. Comments? Wonderings?
What we see happening here in the Termites is an example of emergent behavior. I think of emergent behavior as being something that when it is seen a person says, "Who'd have thunk?"
- click on the setup button, then click the go button
Next Assignment—NetLogo Tutorials
NetLogo has two basic types of programs—agent-based simulations and student-created programs.
The agent-based simulations are typically and illustrate some cute thing or interactions between possibly real-life actors (e.g., chemical reactions, biological processes, objects in space, etc.). They are either instructor developed or their development is guided by an instructor. In theory they can be simple because the agents involved might follow very simple instructions and students "might" be able to create such instruction. However, I would imagine this would rarely create the emergent behavior seen in the Termites program.
Student developed programs, if done by novice programmers will likely involve turtle graphics similar to our drawing in Scratch. Such programs might, however, produce very interesting results or be quite complex.
The NetLogo tutorials activity is being used to familiarize you with the NetLogo environment and let you see some emergent behavior I hope you enjoy it.
Questions? Comments? Wonderings?
Next Time
- We will work on completing the NetLogo tutorials
- Questions? Comments? Wonderings? See you Thursday.