Lesson Plan - Get It!
I'm sure you have used a microwave oven before. Without even thinking, you open its door, put the food in, close the door, and press the number. Then, the microwave oven will do its job by running the motor which rotates the glass plate. As soon as it turns, the microwave energy will cause the water molecules in your food to vibrate. This vibration will increase friction among these molecules, eventually resulting in heat. When the timer is up, the rotating plate stops, and the alarm dings to remind you that its job is complete!
- What if you were asked to tell someone how to use the microwave oven?
- What specific instructions would you give?
Perhaps it would be helpful to keep your instructions very specific in a step-by-step process as shown below.
- Place the food item in a microwaveable container.
- Open the door of the microwave oven.
- Place the food on the middle of the rotating glass plate inside the oven.
- Close the door of the microwave oven.
- Press the number of minutes that you want the food to be heated; then press START.
- When the alarm dings, open the microwave oven and get your food.
Your interaction with the microwave oven is somewhat similar to the operational characteristics of coding: it involves a series of inputs and outputs.
Opening and closing the door, punching in the number of minutes, and pressing the START button describe the inputs triggered by you as a programmer. By performing these inputs, you expect the microwave oven to perform specific functions such as opening and closing the door, running for the allotted time, rotating the glass plate, ringing the alarm, and ultimately heating the food!
In this lesson, you will discover that there is more to coding than a simple set of instructions. Let's get started!
What Is Coding?
The step-by-step instructions on how to operate a microwave oven may sound simple enough, but we have a problem. Computers are unable to read this type of numbered instruction. For example, when you open the door of the microwave oven, the oven's response is not simply allowing you to open it but also to stop emitting microwaves. In other words, you have one input which is opening the door, and the microwave has multiple outputs which are allowing you to open the door, turning on the light, and stopping microwave emission.
Let's break it apart further!
In the same way as the microwave oven, we ask the computer to do a lot of different things, from sending emails to playing games. In reality, computers do not really know what to do by themselves. They need computer programmers to give them a set of instructions in the form of numbers, letters, symbols, or a combination of these. These instructions are called machine codes.
The number codes you see in the above photo do not make a lot of sense to humans. To make it easier for us and the computer to understand the instruction, a programming language is used.
These are just four out of the 698 programming languages that are currently used. Codes are easier to understand because of these languages. For instance, you want the computer to say, "Hello, world." Instead of using a set of numbers or symbols, you can use a programming language as shown below.
- Isn't that easier to understand?
Almost all programming languages work the same way.
- Write the input code and tell the computer what to do: print ("Hello, world")
- The code is compiled to a language that the computer understands.
- The computer executes the code and writes the output "Hello, world" back to you.
In summary, coding is the process of using a programming language to tell the computer what to do.
In the above sample code, there is only one line of instruction. If you want the computer to do more, then multiple lines are written. A document full of lines of code is called a script.
When you see a post on Facebook, for instance, you can press a button to "like" it, "love" it, or choose an emoji that perfectly describes your reaction to the post.
- Can you imagine what the script would be just for this task?
The programmer had to create multiple lines of codes to give instructions to the computer for it to respond to the type of reaction you choose. Once the script is compiled and executed, the programmer can save the script as part of the entire Facebook program. Other apps, websites, and even the online games you play are examples of computer programs.
Learning How to Code
Block-based coding or block based-programming is coding within a programming language where instructions are mainly represented as blocks.
The example above was created using Scratch, which is a block-based visual programming language and an online community developed by the Massachusetts Institute of Technology (MIT) Media Lab. On this website, you can use a block-like interface to create interactive stories, games, and animations.
Code.org is another program that teaches coding. Here, visual blocks can be dragged and dropped to write programs. These programs deliberately use the idea of algorithms. An algorithm is a set of steps that can be followed from start to finish to complete a task.
In block-based coding, you continue to add blocks in order to direct the sequence of events that you want the computer to perform. Here is another more complex example created using Scratch:
You can create free accounts at either (or both!) of these websites to explore and learn more about block-based programming!
- Scratch, a project of the Lifelong Kindergarten Group at the MIT Media Lab
- Code.org, a non-profit organization
Time to head over to the Got It? section to explore different activities that will help you understand the basic computer-coding processes behind every program we enjoy today.