Difference between revisions of "Module Three: Coding to Learn and Learning to Code"
(→Some Fundamental Coding Concepts)
|Line 61:||Line 61:|
Revision as of 23:14, 4 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.
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 Scratched) 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 player 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 player 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 player_choice to save the option that the player entered when playing my game, and I can save the computer's choice to a variable named computer_choice.
Once I have my player 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 player 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 player or the computer made a different choice!
Instead, I have to write code that will work regardless of what choices the player and the computer make. This is an example of an abstraction! Instead of saying "the player 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 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!
Block Coding in Scratch
What is Scratch?
Signing up for a Teacher's Account
Tour of a New Scratch Project
Your First Scratch Project!
Create a Story Video Tutorial