In the Computational Thinking course, we talk about “Abstraction” as the concrete representation of real-world things using computational tools (although there are other definitions, this is what we focus on). Variables are one way to represent things, but there are others. Lately, I have been considering how different variables have different levels of abstraction, and the implications for pedagogy.
Let’s walk through an example. Imagine we have a herd of cows in a field.
This herd could be represented quantitatively using the following table.
At the bottom row of this table, we see an “average” cow. There is no “average cow” in our herd with a weight of 716 pounds. But we understand this idea of an “average cow” as an abstraction.
Now, how would we represent this herd in a BlockPy program?
We now have a variable that abstracts our herd of cows into a list of numbers, which can be easily manipulated. By abstracting our cows, we reduce unnecessary information (their height, their name, their genetic code, how many times they’ve mooed today, etc.).
We can create a variable that represents our imaginary average cow.
We cannot see the value of the
average_cow from this perspective, although we could print out its value. It is a more abstract variable, dependent on the order of execution and pre-existing variables.
We used built-in Python functions to quickly compute that average, but in the CT course, we don’t allow students to do so. Instead, they have to use a for-each loop. The necessary code to calculate the average cow weight would be:
This code has 5 variables:
total_cows are similar to the
average_cow variable, but they are at a higher level of abstraction than
my_cows since they do not represent real physical entities.
- How did we know to create
- How did we know what to initialize them to?
- How did we know to place them inside the loop to manipulate them?
And what about that
a_cow variable? It represents each cow, but only over the entire course of the loop. It is not a specific cow until a specific time. To me, this represents an even higher level of abstraction than the other variables.
- What is the relationship between
- How do I mentally model this abstract cow?
- How do I keep track of the cow over “time”, when “time” is not immediately present in the program as written?
Looking at a completed program, I think many students are not able to recognize the varying levels of abstraction of these variables, and they struggle with writing this all from scratch.