Module Three: Coding to Learn and Learning to Code
- 1 What is it Actually Like to Code?
- 2 What is it like to Learn to Code?
- 3 Some Fundamental Coding Concepts
- 4 Block Coding in Scratch
- 5 Your First Scratch Project!
- 6 Troubleshooting (on your own and with students)
- 7 Peer collaboration
- 8 Building student self-efficacy
- 9 Reflection and Community Building
- 10 Module Navigation Links
- 11 Get in Touch!
What is it Actually Like to Code?
Coding is a bit like trying to have an instructive conversation with a young child who does not speak the same languages as you, and you only have a vague idea of what language she does speak. Unlike the child, however, the computer will not be trying to figure out a way to communicate back with you.
My uncle used to love to tell me that "a computer is nothing more than a fast idiot". Things have changed a lot in the technology landscape since then, but when it comes to the type of coding we'll do in this course, and what most people are likely to learn, this is still resoundingly true.
Computers will do what you instruct them to do, exactly.
Have you ever worked with a child who followed your explicit instructions to the letter, with a result that was inconsistent with what you actually meant? This is not an unusual result when you are writing a computer program. It's not that computers are trying to be maliciously compliant, it's that they do not make any allowances for cognitive leaps or metaphorical speaking, in any sense. If you tell a computer to drive 50mph south, it will drive south at 50mph no matter what obstacles appear in the way, no matter how many stop signs appear, no matter what bodies of water stand between it and due south.
Computers will ONLY do what you instruct them to do.
When you write instructions for a computer, you have to be incredibly meticulous, and cover every single step in a decision-making process to get the results you want. The computer will not infer anything that is not explicitly written, and it won't bridge a gap if you neglect to explain a part of the thinking process.
If you've ever tried to convince a teenager to clean their room, you may understand exactly what I mean here. They may have "cleaned their room", but perhaps the silverware never made it into the dishwasher. They may have "cleaned their room", but their dirty laundry may have been shoved under the bed instead of into the laundry hamper.
To get the result you want out of a computer program, you have to include absolutely everything you want it to do from beginning to end, without leaving anything out.
Computers cannot overlook typos, misplaced parentheses, or other syntactical errors.
To a computer program, "code" and "Code" are two different words because a capital C and a lower case c are not the same character. Similarly, a colon and semicolon are different characters. A computer program will not run if 99.9% of the code is written correctly, because it will get stuck on the place where you left an extra space or didn't indent to the correct degree. The vast majority of problems I've had to fix when writing programs were typos, most of which were absolutely tiny and therefor took forever to find.
Fortunately, modern coding programs (called IDEs, or Integrated Development Environments) make it a lot easier to find the errors in your code!
A lot of trial, and nearly as much error.
Having worked with a lot of programmers over the last decade or so, I can tell you that the trial and error process in coding never really ends, no matter how long you've been doing it. Languages are constantly being updated and expanded, which languages are in popular use is always changing, and since no two pieces of software are the same, the types of problems you'll try to solve with programming will always be new and different.
In the beginning, new coders tend to assume that they're fighting with their code because they're just not good at coding, and you may hear this from students a lot. In reality, though, coding means solving problems in collaboration with a partner that is inflexible and unwilling to meet you half way.
When frustration hits (and it will!) the best option is to take a break and come back later with a clear head to try again.
Here's a video of me fighting with my code, in case you don't believe me.
Video: The Struggle
What is it like to Learn to Code?
Learning to code is a lot like coding itself in that there is likely to be a lot of trial and error in the process of learning and becoming comfortable with coding. Specifically, to learn how to code in a regular coding language, there are two separate parts that need to be mastered,
- The fundamental concepts of coding, some of which are introduced below, and
- The syntax of the language you are learning to write code in.
In the beginning, it can be very difficult to tell which part you are struggling with as you create your first projects. This is part of the reason that block coding platforms (like Scratch) were developed to help new coders! We'll talk about Scratch more in the next section!
For now, I recorded this video to talk more about what you can expect when you're learning to code!
Video: What to Expect When Learning to Code
Some Fundamental Coding Concepts
In math, we use variables in the place of missing information in an equation. We do this in coding, too, but coding uses variables in a wider variety of ways than math does. We can use lots of different kind of information in coding, not just numbers!
Let's say that I want to make a computer version of Rock, Paper, Scissors where a user competes against the computer. At some point in my game, I will need to keep track of what option the computer chose, and which option the user chose. In order to have my program remember this information long enough for the game to run, I need to save it somehow. This is one aspect of what variables do - they allow us to remember a piece of information by assigning a name to it. For example, I can create a variable named user_choice to save the option that the user entered when playing my game, and I can save the computer's choice to a variable named computer_choice.
Once I have my user and computer choices saved, I can then compare them to figure out who won the game. This is the second aspect of what variables do in computer programs - they allow us to write instructions for a process when we don't know what the real information is going to be at any given moment. In my Rock, Paper, Scissors game, for example, I don't know what the user or the computer will pick when I'm writing the game, so I can't write my code with those details. Even if I could write my code that specifically, my game would fail if either the user or the computer made a different choice!
Instead, I have to write code that will work regardless of what choices the user and the computer make. This is an example of an abstraction! Instead of saying "the user chose rock and the computer chose paper, therefor the computer wins", I have to create a set of steps to allow the program to determine who wins in multiple possible scenarios! Variables make this a lot easier, because I can use them to insert the real values into the decision-making algorithm when the game is actually run.
Play to Learn
This is a Rock, Paper, Scissors game I built in Python. Click the link to open the game, then click the green Run button at the top of the page, and follow the instructions in the right-hand column to play. I love using Python and teaching it to kids because it's fairly readable, as programming languages go. Take a look at the code in the middle section of the page and see if you can follow what's going on! You can also check out the expanded version I made with students, Rock, Paper, Scissors, Lizard, Spock!
Data types are the different kinds of information that we can save in our variables. Generally, these include things like:
- Integers (numbers without a decimal)
- Floats (numbers with a decimal)
- Strings (any string of characters, usually words or sentences, such as the user_choice and computer_choice examples above)
- Lists (which contain more than one value, which can belong to different data types)
- Booleans (which are either/or variables, which are set to either "true" or "false")
I'm sure you've used comparison operators already, even if you were a K-12 student the last time you did! Comparison operators are symbols we use in coding to compare two different pieces of information. Here are a few examples:
|Operator Symbol||Operator Name||What it Does|
|<||"Less Than"||Compares two numerical values to determine if the value on the left is less than the value on the right.|
|>||"Greater Than"||Compares two numerical values to determine if the value on the left is greater than the value on the right.|
|<=||"Less Than or Equal To"||Compares two numerical values to determine if the value on the left is less than or equal to the value on the right.|
|>=||"Greater Than or Equal To"||Compares two numerical values to determine if the value on the left is greater than or equal to the value on the right.|
|==||"Equal To"||Compares two numerical values to determine if their values are the same.|
|!=||"Not Equal To"||Compares two numerical values to determine if their values are different.|
When using comparison operators, the answer to each comparison will either be "true" or "false". For example, 5 < 10 would be true, while 6 > 10 would be false. When coding, we would say that a "comparison statement returns a boolean value of true or false". Returns just means the program has given us a result for a certain segment of code.
Conditional statements are the parts of computer code that help a program to make a decision about what to do next. For example, in the Rock, Paper, Scissors game above, one conditional statement we include might be something like:
"If the player chooses scissors, and the computer chooses paper, then the player wins the game."
Most coding languages will actually use some variety of the words if, then, and else in these kinds of statements to determine the programs next steps. We also use these kinds of thought processes when we make decisions, even if we don't realize it. For example, when you decide what to wear on a given day, you may think something like:
"If it is cold, then I will wear a jacket. If not (else), (then) I will wear a shirt with short sleeves and no jacket."
A function is a section of code that is meant to complete a set of actions with a desired result. We give these sections of code a name so that we can use them over and over again in the same program.
Let's say I'm writing a computer program to bake cookies. My code may have multiple functions in it to cover the entire cookie-making process, but somewhere in there, I will build a function called bakeCookies() for the actual baking step. That function might look something like this:
define bakeCookies(number_of_minutes, baking_temperature, preheat_time): preheat oven to baking_temperature wait preheat_time minutes put cookies into oven wait number_of_minutes remove cookies from oven
In this pseudocode example, my bakeCookies() function needs three pieces of information (variables):
- number_of_minutes, which is how long my cookies should stay in the oven
- baking_temperature, which is how hot the oven should be
- preheat_time, which is how long it will take the oven to heat up
Once I have written the code for my bakeCookies() function, I can then use it for any cookie recipe I want by setting the appropriate values for my variables for the cookies I want to bake!
A loop is exactly what it sounds like - a bit of code where the instructions repeat. The instructions on the back of a bottle of shampoo ("lather, rinse, repeat") are an example of a loop.
There are different kinds of loops in coding, depending on the type of results you're looking for and which language or tool you're using.
- An iteration loop is when you run a series of instructions for either a specific number of times, or to process the items on a list in some way. For example, if I were to write an interation loop for washing the dishes in pseudocode, it might look something like this:
for each dish in dirty_dishes: pick up dish scrub dish with soapy sponge rinse soap off of dish place dish in drying rack
If I were to follow these instructions like a computer program, I would keep going through these steps over and over again until all the dishes were washed.
- A while loop keeps running the same steps while a particular condition is still true. For example, here are a couple of real-world while loops that may sound familiar to you:
while pandemic = true wear mask in public
while homework != finished work on homework
Play to Learn
Here is a Dance Party Game I built using Scratch. Click the Green Flag button to start the Dance Party, and notice the repetition in the dance animations. Then, click the See Inside button in the upper right corner to see the game's code. You'll notice a few Forever loops, and a few Repeat loops that made it much easier to finish the code for the game!
Block Coding in Scratch
What is Scratch?
Scratch is a visual programming language (or VPL) that was created by MIT Media Lab to help people learn to code. Officially, Scratch is meant for children age 8-16, though it is such a fun platform to use that plenty of adults program in Scratch, and I've known children as young as 6 years old to do just fine building their own programs! People all over the world use Scratch, and it is now available in over 50 different languages.
To help children begin learning even earlier, the MIT Media Lab later released a version for even younger children called Scratch Jr. In Scratch Jr., the blocks have symbols rather than words for children who cannot read yet. The interface is also simpler, and because the program is downloaded on a tablet rather than accessed on a website, young children interact with the application without encountering other users online as older children do in Scratch.
The rest of the materials in this section will help you get to know Scratch, sign up for a Teacher's Account, and understand different parts of the platform.
Signing up for a Teacher's Account
Creating a teacher's account in Scratch is very useful if you intend to use Scratch in the classroom! It allows you to create student accounts that are connected to your teacher account, without having to provide an email address for the students. This also allows you to reset student passwords easily from within your account! When student accounts are created independently with an email address (usually their parents'), you will have a hard time unlocking their accounts in class if the students are not able to access emails at the provided address!
You will also see student activities on Scratch, which will allow you to view the projects they share, as well as see their comments on other people's projects. This allows you to see if they are posting inappropriate comments or participating in other sorts of behavior that may need to be addressed.
You can read more about teacher's accounts here: Teacher Account FAQs
Click here to register for a teacher's account! Keep in mind that it takes time for your teacher's account to be verified (usually less than a week), so plan to do this in advance before starting projects in the classroom! The video below will walk you through the process of requesting a teacher's account.
Scratch Reference Guide
This reference guide is designed to help you get the lay of the land once you've logged in to your new Scratch account! You can download and save it as a PDF for easy use later on.
Tour of a New Scratch Project
This video will help you get better acquainted with the Create Page in Scratch to help prepare you to build your first Scratch project!
Your First Scratch Project!
The project tutorial video below is meant to guide you through building your first Scratch story, and demonstrates the following skills in Scratch:
- Adding new sprites to a project
- Adding new backdrops to a project
- Switching costumes for your sprites
- Making sprites speak by displaying text bubbles on the screen
- Selecting an appropriate Event to start code block stacks
- Using loops to repeat segments of code
- Animating characters while stationary and while moving
- Adding built in sounds to your projects
- Using broadcasting and messages to control the flow of events in a project
- Recording your own narration for your sprites
- Adding the Text-to-Speech plugin to your Scratch project
- Using Text-to-Speech to add narration to your project
You can also use any of the Tutorials in Scratch to create your first project! To use a tutorial, go to the Create page as shown in the video, then click the Tutorials link at the top of the page. Click on the tutorial you want to use, and it will open in the Create page where you can follow the instructions to build your project.
Create a Story Video Tutorial
Remixing to Learn
You don't have to start with a blank project if you'd rather experiment with a project that's already been built. You can also Remix an existing project! When you remix a project, you copy the project into your account, where you can make changes, customize, and experiment with the project's code to make it into a new project that's all your own! Watch the video below for more information, and then check out the links to projects I've built below. You can also browse through the other projects in the Explore section of Scratch and find another project that interests you!
Botanical Garden Project (from the tutorial video above)
Troubleshooting (on your own and with students)
The best thing you can do to make troubleshooting easier is to test your Scratch projects constantly! It's a lot easier to spot problems in your game if you play test your projects after each new step you add to the game. Then, if you find a problem, you only have to check a few things to figure out why it's not working the way you want it to!
Here are some other tips to help make your project-building experiences more fun and less frustrating:
- Once you add multiple sprites, it can be VERY easy to put coding blocks onto the wrong sprite by mistake. Always look at the sprite watermark in the upper-right corner of the Coding Palette to verify who you're giving instructions to!
- You can click on a stack of blocks to run just the instructions in that stack. This is definitely helpful when your project has gotten long and you don't want to run the entire thing to play test every time you add a few more coding blocks.
- If you want to make big changes to your project and you're nervous about how those changes will turn out, you can make a copy of your project just in case you later decide you don't like the changes. To do this, click on the File link in the menu at the top of the page, then select Save as a Copy from the drop-down menu that appears.
Whenever possible, letting students work together on projects can help them learn from one another and practice their trouble-shooting and tolerance for trial-and-error. Even if students are working on individual projects, allowing them to ask one another for help troubleshooting goes a long way toward building student independence for future projects. Students also tend to get ideas from looking at one another's projects, so you may find that their collaboration leads to new discoveries about blocks and coding options that you never thought to try!
Building student self-efficacy
For as long as I've been building projects in Scratch, I still make mistakes frequently when teaching others how to build their own projects. Sometimes this happens in front of an entire classroom full of students. While no one likes making mistakes publicly, I've learned that these moments have great benefits for students. Here's why:
- If the teacher can make mistakes, they know it's not the end of the world when they make mistakes, and they know that making mistakes doesn't mean you're not capable.
- When I make a mistake, I point it out to the class as soon as I notice it. Then I laugh about it, fix it, and we move on. I make a careful point to never show embarrassment at my mistakes in front of students.
- If a student notices my mistake before I do, which happens frequently, I make sure to thank them for helping me with my project. I then explain the mistake I made to the whole class, and thank the student who caught it again, by name, in front of the whole class.
- If we're trying something new to try and build something in a project, I'm always honest with students that I'm not sure how to make it work, and that we'll just keep trying until we figure it out. If something doesn't work, I'll write it on the board so that we can keep track of what we've already tried. Every time something doesn't work, I remind students that we're one step closer to finding the method that will work! In my experience, this prompts students to venture ideas much more readily, without being afraid of what will happen if their idea doesn't work! You might even let students write their ideas on the board when they don't work and congratulate them for proposing a possible solution.
- When mistakes happen, whether your own or students', talk through it with the class, and ask students if they understand why it didn't work. If you can learn something new from the mistake, and make that learning visible, then the mistake turns into a victory and new information for future projects!
You can also write mistakes into your plans for projects with your students. I often tell students that almost no coding project ever works the first time, which is true. If you run your project and even part of it works, you're still well on your way to a project that does everything you want it to do, which is a huge victory. When we make troubleshooting a planned and expected part of the process, students will soon get to a point where they don't even notice the bumps in the road on the way to a finished project.
You will also have plenty of times where students figure out how to do something new in Scratch that you've never done before. These moments are some of my favorites because I get to learn something new, and my students get to see that even teachers don't know everything! When this happens, give the student a chance to show what they've learned to the other students in the class and teach them how to do it themselves. You may even find that other students get ideas and contribute even more exciting new ideas to the conversation!
Reflection and Community Building
How did your first Scratch project go? Did you build something you'd love to share? Do you have questions, or want to discuss Scratch projects with other teachers?
Get in Touch!
Are you interested in learning more, or continuing the coding conversation with other educators? You can get in touch with me via my website at www.technicallystacy.com. I would love to hear any feedback you have about my mini-course!