Difference between revisions of "Module Three: Coding to Learn and Learning to Code"

(Block Coding in Scratch)
(Block Coding in Scratch)
Line 187: Line 187:
 
<big>'''Scratch Reference Guide'''</big>
 
<big>'''Scratch Reference Guide'''</big>
  
[[File:Screen Shot 2020-05-09 at 11.13.23 PM.png|thumb|left|Scratch Reference Guide cover image]]
+
[[File:Screen Shot 2020-05-09 at 11.13.23 PM.png|frame|left|Scratch Reference Guide cover image]]
  
  

Revision as of 23:15, 9 May 2020

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.

(GIF of Homer Simpson from The Simpsons, from GIFER.com.)

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.

(A GIF of three very confused pugs, from GIFER.com.)

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 GIF of a person typing with boxing gloves on, from GIFER.com.

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,

  1. The fundamental concepts of coding, some of which are introduced below, and
  2. 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

Variables

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 aspects 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

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")


Comparison Operators

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

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."

Functions

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!


Loops

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.

Like other visual programming languages, the goal of Scratch is to reduce the cognitive load of learning to code. When learning other programming language, such as Python or JavaScript, new coding students need to learn both the fundamental concepts of coding AND a lot of complicated language syntax at the same time. With visual programming languages, the syntax is made much simpler by using coding blocks that can be arranged to build a program. This helps new coders learn the concepts that make computer programming works before they begin to learn their first text coding language.

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.

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

Scratch Reference Guide cover image


File:Scratch Reference Guide.pdf


Tour of a New Scratch Project

Your First Scratch Project!

Create a Story Video Tutorial


Remixing to Learn

Troubleshooting (on your own and with students)

Peer collaboration

Building student self-efficacy

Module Navigation Links

Module Two: Computational Thinking and How to Teach It | Module Four: Integrating Coding Lessons into the Curriculum