Lesson 4: Using Simple Commands
Overview
This lesson is a student's first exposure to programming in App Lab. The lesson begins with a quick reflection prompt. Then students are introduced to the practice of pair programming before beginning to program. For this lesson the students' view is limited to only a very few simple “turtle” commands to draw graphics on the screen. After a few warm up exercises, using only combinations of four drawing commands, students must figure out the most “efficient” way to draw an image of a 3x3 grid. The lesson concludes with a sense-making discussion about the meaning of efficiency in programming and the reason behind beginning with such a limited set of programming tools.
Purpose
The overarching purpose of this lesson is to start students on their programming journey on the right foot. It should feel like a natural extension of the collaborative problem-solving they've done so far in the course.
One way this is done is by introducing pair programming, a pedagogy with demonstrated benefits on student learning and attitudes. While you shouldn't use pair programming every time students program, introducing the practice early means you can call back to it when appropriate through the rest of the unit.
This lesson also aims to frame programming as a creative problem-solving discipline. One way this is done is by limiting students to a small set of commands, namely moveForward
, turnLeft
, penUp
and penDown
. These constraints move the focus from memorizing commands and syntax to creatively examining problems, iterating on ideas, and collaborating with peers. The closing remarks highlight the value of these constraints and the authenticity of needing to program with seemingly limited commands.
Agenda
Getting Started (10 mins)
Activity (30 mins)
Wrap-up (15 mins)
Extended Learning
Assessment
View on Code Studio
Objectives
Students will be able to:
- Use App Lab to write programs that create simple drawings with “turtle graphics.”
- Create a program with a partner following the pair programming model
- Explain different ways one might measure the efficiency of a program.
Preparation
- Practice the levels yourself so you're familiar with the challenges.
- Familiarize yourself with opening remarks and comments for background knowledge.
Links
Heads Up! Please make a copy of any documents you plan to share with students.
For the Students
Vocabulary
- Pair Programming - A method of programming in which two programmers write code using a single computer. One programmer in the "driver" role uses the mouse and keyboard to actually write the code while a second acts as a "navigator", keeping track of the big picture, catching errors, and making suggestions. Programmers switch roles frequently and communicate throughout the process.
- Turtle Programming - a classic method for learning programming with commands to control movement and drawing of an on-screen robot called a "turtle". The turtle hearkens back to early implementations in which children programmed a physical robot whose dome-like shape was reminiscent of a turtle.
Introduced Code
Teaching Guide
Getting Started (10 mins)
Transitioning to Programming
Discussion Goal
Goal: This should be a quick discussion aimed at building confidence. Many students are likely excited to program, but others may be apprehensive. This prompt and the following quick words should be used to quickly reassure students they've already practiced many skills necessary to learn programming. They're ready for this!
Obviously you can't control what responses students will give, but once you've heard a few students advise students to stick with it, or check their work carefully, etc. you're likely able to summarize and move on.
Prompt: Think back over the human machine language lessons we just completed. Write down some advice or encouragement you'd give to students in next year's class before they complete those same lessons. What attitudes or skills will be important?
Discuss: Have students silently journal responses. Then have them share with partners. Then discuss with the whole class. You may want to record their responses on the board.
Remarks
These are some great pieces of advice. Now I'm going to reveal that this advice isn't really for next year's students, but for all of you! Today we're going to begin programming on the computer, and while that's obviously different from the human machine language activities we just completed, a lot will be the same. You'll need to stick with it, pay attention to detail, and collaborate with others. In fact, before we jump in there's one new collaboration skill I want to teach you all.
Introduce Pair Programming
Teaching Tip
Pair Programming: Pair programming is practiced in education and in industry. Students who pair program are more confident in their abilities and are more likely to continue to study computer science. This practice is most effective if it is introduced early and the rules for switching partners are enforced by the teacher. You can read more about Pair Programming in the Computer Science Principles Curriculum Guide on page 8.
Enforcing Timing: A particularly important role of the teacher of this lesson is introducing the logistics of pair programming. Enforce students trading who is driver or navigator every few minutes (3 minutes). Use a timer and actually force pairs to show you that they are switching roles.
When to Use Pair Programming: You don't need to always pair program. You may even opt to stop pair programming after 15 minutes or so of this lesson. Introducing the practice early and reinforcing its value will ensure it's a practice you can return to throughout this unit.
Here is a helpful video to show students to explain Pair Programming: Pair Programming CSP
Remarks
Today we'll be using a practice called pair programming. Pair progamming helps people make better programs by working together. The main idea is that two programmers use a single computer to collaboratively develop code. There's a few rules to make sure this system works effectively.
Review: Introduce the rules of pair programming below.
- There is only one computer and two programmers.
- Assign one student "driver" and the other "navigator". Don't worry, you'll switch often.
- The driver is the only one to touch the keyboard/mouse.
- The navigator should look for problems in the code and keep track of the high-level plan.
- Both driver and navigator should be communicating constantly by talking out loud and sharing ideas.
- Driver and navigator roles must switch when the teacher indicates, typically every 3-5 minutes.
Activity (30 mins)
Move to App Lab
Group: Place students in pairs. If you need to make one group of three you may do so and assign two members at each time to be "navigators".
Remarks
To get you situated in App Lab there's a quick video. Once everyone is through that we'll get started. I'll keep track of time and remind you to switch who is driver and navigator every 3 minutes or so. Make sure you're ready to switch by talking out loud and sharing ideas.
Wrap-up (15 mins)
Discussion: What does “efficiency” mean when programming?
Compare Solutions and Discuss: Each pair of students should get together with another pair to compare their solutions for each of the three problems to determine which is the most efficient. Once they have shared and compared their solutions they can consider the questions below.
- What strategies or reasoning did you use to identify possible solutions?
- Is the solution that you or another group found the most efficient? How do you know?
Prompt: What is the “most efficient” way to program the solution for the 3x3 grid?
Discussion Goal
The point of this discussion is to highlight the fact that "efficiency" can mean different things depending on the context.
Potential answers to this question can include the time they take to run on a computer, the time or number of people they require to create, the number of resources they require to run, etc. Students will likely come up with others.
Don’t fixate on any one solution and encourage students to come up with the most comprehensive list possible.
Discuss: Have students share at their tables before moving to a full class discussion.
Prompts:
-
Today’s activity challenged us to find the most efficient solution to a problem. We care about efficiency when we don’t want to waste something valuable, like money, time, or space. We measured the efficiency of our programs in terms of lines of code, but there are other ways to think about efficiency when talking about code or programs that run on a computer. When we try to create efficient programs, what other valuable resources might we be concerned about conserving?
-
List the things that students come up with somewhere that can be read by the class. These can be used to motivate portions of the next and future lessons.
What's the point? Why constrain to 4 commands
Teaching Tip
- There are a lot of points in this “What’s the Point?” section. They all go together and they are not all points you have to make in this lesson right now.
- You should keep these big ideas in your back pocket, because you may want to refer back them in the future.
- The short version:
- Creativity in programming comes from the fact that all programming languages have constraints; your job is to figure out how to use the language to get the computer to do what you want it to do or to solve a problem.
- Collaboration is a huge help when solving problems with programming. It’s helpful to work through problems with a partner.
Remarks
Why did we constrain you to only working with 4 possible commands? We begin programming with only a few commands for a few main reasons:
- What you did today is what you always do when programming: use a language to express a solution to a problem. Collaborative problem-solving skills are important factors in programming. Being able to get together with other people to talk about and make reasoned arguments about the best ways to code things is what professionals do.
- Learning to program isn’t just a matter of memorizing commands. The art of programming - the creative part - is always about understanding how to use the features of a programming language to solve a problem.
- Whether you know 4 commands of a language or hundreds, you will always be constrained by the programming language. The reason you need to learn how to program is because there isn’t a command to do every little thing; you have to understand the set of things that a programming language can do, and then use your creativity and problem-solving skills to get the computer to do what you want.
- In this class, we will repeatedly run into the challenges we encountered today. Even seemingly simple problems will require us to creatively apply the tools we have available: the commands or instructions provided by the programming language.
- Multiple approaches are always possible to solve a problem. Furthermore, we may never be sure we have found the most efficient one. We may not even agree about how we should measure efficiency.
- As we saw today, even when designing programs using four commands to draw with a turtle, the solutions are not always easy. We will definitely need to keep practicing as we start tackling more complex challenges.
Extended Learning
Ask students to propose ways they could prove that their solution to the 3x3 grid problem is the most efficient. Note: An actual proof is very challenging.
Assessment
Criteria for 3-by-3 Grid:
- If you want to assess students’ programs (especially 3x3 grid) you can see their work in the answer viewer and you might look for the following criteria:
- The program draws the desired figure.
- The turtle is returned to its starting location and is pointed in the correct direction.
- The figure is located in the correct position, relative to the starting position of the turtle.
- The program only makes use of the “building block” commands provided.
- The program is reasonably efficient in its execution.
Online Questions: A set of assessment / reflection questions is available on Code Studio.
- Lesson Overview
- Student Overview
- Video: Turtle Programming
- Student Overview
Teaching Tip
The constraint of working with only 4 commands is important. (See: “What’s the Point?” below.) If students come to the class with prior knowledge of programming they might try to go outside these constraints to reduce the number of lines of code.
If you see students using commands beyond the 4 provided - or using parameters with those commands like: moveForward(150)
, you should tell them that they are not solving the problem; the problem is to create the images using only the 4 commands provided.
Student Instructions
Given only 4 turtle commands, write code in App Lab to complete the drawings in each of the challenges below. Your goal is to write code that solves the problem as efficiently as possible using only the commands provided.
What does “efficient” mean? In computer science it can actually mean several different things depending on what you’re talking about. Work on these challenges, try to solve them in a way that you think is best and we’ll ask about efficiency at the end.
Do This:
Draw a 1 x 1 square to the front and left of the turtle as efficiently as possible. The program should stop with turtle in its original position, facing its original direction.
Once you think you have a solution, click the Finish button - it will appear once you run the program.
Teaching Tip
The insight here is that we can turn right by turning left 3 times.
Student Instructions
Do This:
This time, draw a 1 x 1 square to the front and right of the turtle as efficiently as possible. Notice that there is no command to turn right! You need to figure out how to draw this by only turning left and moving forward. The program should stop with turtle in its original position, facing its original direction.
When you're done click the Finish button to move onto the next problem.
- Challenge: Draw a 3x3 Grid Using Turtle Commands
- 5
Teaching Tip
-
Students will need some time to work on the 3x3 grid problem; it is more challenging than it appears at first. * Students will ask you if you know the least possible number of lines of code needed to draw the 3x3 grid. Rather than giving an answer, ask student pairs to compare their solutions with other pairs. If they agree on a solution, see if you get a class consensus.
-
You can also ask: Can you do it with fewer commands? If not, can you prove that it’s impossible to do with fewer?
-
Questions like these are the kinds that programmers ask each other all the time. And programmers usually work with each other to reach a solution.
-
An example of a solution is given in the teacher tab for the problem in Code Studio, but it is just an example; there are millions of ways to do the 3x3 grid.
Student Instructions
Do This:
Draw a 3x3 grid to the front and right of the turtle as efficiently as possible. The turtle should end at its original location, facing its original direction.
HINT: This problem presents some subtle challenges. Work with your partner to discuss possible solutions. Try more than one path. Testing your ideas on paper might be a faster way to brainstorm.
Student Instructions
This lesson introduced the notion of "efficiency" in programming, and that it might mean different things at different times. Think of an example outside of computer science in which you have heard the term “efficiency” and compare it to the ways we talked about efficiency in programming.
In what ways is the meaning of "efficiency" the same? In what ways is it different?
Student Instructions
Today we solved a series of problems with a limited set of commands (only 4). Give at least one reason why it's useful to learn how to solve and program solutions with a limited set of commands.
Student Instructions
In this lesson you wrote code to make the turtle draw squares. Briefly describe how the code for drawing a rectangle would be different than drawing a square. (Example rectangle at right)
Student Instructions
Summarize your experiences with this first App Lab lesson by answering the following questions:
- What surprised you about programming with such a small set of basic commands?
- Were you able to be creative with such a limited set of tools?
- What was most frustrating about this activity? If you could add one additional simple command, what would it be and why?
Standards Alignment
View full course alignment
CSTA K-12 Computer Science Standards (2011)
CL - Collaboration
- CL.L2:3 - Collaborate with peers, experts and others using collaborative practices such as pair programming, working in project teams and participating in-group active learning activities.
CPP - Computing Practice & Programming
- CPP.L2:4 - Demonstrate an understanding of algorithms and their practical application.
- CPP.L2:8 - Demonstrate dispositions amenable to open-ended problem solving and programming (e.g., comfort with complexity, persistence, brainstorming, adaptability, patience, propensity to tinker, creativity, accepting challenge).
- CPP.L3A:3 - Use various debugging and testing methods to ensure program correctness (e.g., test cases, unit testing, white box, black box, integration testing)
- CPP.L3A:4 - Apply analysis, design, and implementation techniques to solve problems (e.g., use one or more software lifecycle models).
CT - Computational Thinking
- CT.L2:1 - Use the basic steps in algorithmic problem-solving to design solutions (e.g., problem statement and exploration, examination of sample instances, design, implementing a solution, testing and evaluation).
- CT.L2:3 - Define an algorithm as a sequence of instructions that can be processed by a computer.
- CT.L2:6 - Describe and analyze a sequence of instructions being followed (e.g., describe a character’s behavior in a video game as driven by rules and algorithms).
Computer Science Principles
5.1 - Programs can be developed for creative expression, to satisfy personal curiosity, to create new knowledge, or to solve problems (to help people, organizations, or society).
5.1.2 - Develop a correct program to solve problems. [P2]
- 5.1.2A - An iterative process of program development helps in developing a correct program to solve problems.
- 5.1.2I - A programmer’s knowledge and skill affects how a program is developed and how it is used to solve a problem.
5.1.3 - Collaborate to develop a program. [P6]
- 5.1.3B - Collaboration facilitates multiple perspectives in developing ideas for solving problems by programming.
- 5.1.3C - Collaboration in the iterative development of a program requires different skills than developing a program alone.
- 5.1.3D - Collaboration can make it easier to find and correct errors when developing programs.
- 5.1.3F - Effective communication between participants is required for successful collaboration when developing programs.
5.2 - People write programs to execute algorithms.
5.2.1 - Explain how programs implement algorithms. [P3]
- 5.2.1A - Algorithms are implemented using program instructions that are processed during program execution.
- 5.2.1B - Program instructions are executed sequentially.
5.4 - Programs are developed, maintained, and used by people for different purposes.
5.4.1 - Evaluate the correctness of a program. [P4]
- 5.4.1A - Program style can affect the determination of program correctness.
- 5.4.1D - Longer code blocks are harder to reason about than shorter code blocks in a program.
- 5.4.1E - Locating and correcting errors in a program is called debugging the program.
- 5.4.1I - Programmers justify and explain a program’s correctness.
CSTA K-12 Computer Science Standards (2017)
AP - Algorithms & Programming
- 3A-AP-13 - Create prototypes that use algorithms to solve computational problems by leveraging prior student knowledge and personal interests.
- 3B-AP-11 - Evaluate algorithms in terms of their efficiency, correctness, and clarity.