Among the computing principles, the COMPUTATION category is the most impressive one. The computation category addresses the problem of converting complex problems into a number of computational steps to achieve a solution.
When I was learning Python on campus, in order to solve a problem, the tutor always started with a flowchart. For example, if she wanted to print out “Hello World” for 5 times, here is her workflow:
First, she would draw a flowchart:
Computational thinking is a way humans solve problems. In the process of drawing the flowchart, we are thinking in human’s way. Print out “Hello World” for 5 times, intuitively we have to define how many times and what to print, and then print it out. These steps in our mind are exactly depicted by the flowchart, as well as the code.
| while loop |
i = 0
nbrTimesToPrint = 5
while (i < nbrTimesToPrint) :
print(‘Hello World’)
i = i+1
In the code, we use the variable i as a counter to count from 0 to 4, which is 5 times. Using the while loop, the little program repeats the “print” action for 5 times in only 5 lines. The number of the lines will be the same even if we want to print it out for hundreds of times, thousands of times.
Therefore, the advantage of the abstraction is manifest. If you cannot abstract “printing ‘Hello World’ for 5 times” as a repeating process, it is impossible for you to think about having a loop in your code. The flowchart will be like this:
and the code will be:
print(‘Hello World’)
print(‘Hello World’)
print(‘Hello World’)
print(‘Hello World’)
print(‘Hello World’)
The number of lines is the same as the loop one; this version of code is even more explicit. It is coder’s call. For now, the requirements are easy to meet with: even with the second one without loop, the problem can still be solved in a few lines, but for further consideration, the loop one is more advantageous for sure.
It should be noted that human thinking come first and then computational thinking. The decision of whether to loop or directly to command for 5 times, has been made in human’s mind. The idea of loop is not taught by the computation or software; it is our developed logical thinking that enables us to simplify the steps by making use of loop.
We can observe the existence of RECURSION from this tiny program as well. Making use of the value of the counter variable i, with the comparing between the counter and the variable nbrTimesToPrint, the program knows when to stop. As we can see, the counter i needs an initial value i=0, and then with i = i+1 at the end of the program, the counter adds 1 when the program run through the whole process for one time. The counter is the descriptive feature of the program accounting for how many times the program has run, and it is this value that determines the end of the program.
Computing is the automation of abstractions. Computational thinking focuses on the process of abstraction. The computation and software rely on human minds, and by writing out the codes, human have a chance to recount what’s going on in their minds in an observable way.
Reference: