Should We Teach All Children How to Code?

"Hour of Code" received a great boost when the commander-in-chief of the most powerful country became a "coder-in-chief". This was part of the the Computer Science Education Week which run from December 8 through 14. Last Monday, both President Obama and Vice President Biden participated in coding exercises with students.

Above photo captured from YouTube video

Vice President Joe Biden visits with students and is taught to write a line of code, during the "Hour of Code" event in the Eisenhower Executive Office Building, in Washington, D.C., Dec. 8, 2014. (Official White House Photo by David Lienemann)
Even my son, a third grader at Mason Crest Elementary School, got a taste of how coding works. The school's website now even has links to coding activities designed for elementary school students:


Similar to what Obama and Biden were doing, my son needed to select line by line instructions to help Angry Red Bird find Silly Pig:

Above captured from code.org
By choosing instructions from the various blocks listed above, an assembly of steps is constructed. The above is then translated to a script that looks like this:

Above captured from code.org
I learned computer programming when I was already a senior in college, about thirty years ago. Of course, there were no Angry Birds yet at that time but I did manage to write a program that played five-card draw poker. This homework took me several days. First, I thought that it was really challenging to teach a computer on how to evaluate what was present in five cards. The program needed to check for four of a kind, flush, straight, full house, straight, three of a kind, two pairs, one pair, and a high card. To play multiple games, cards also needed to be shuffled. I also had to make sure that no card is drawn twice. All of these tasks seem straightforward to anyone who knows how to play poker, but I realized that for coding, I really needed to start from scratch. Before I started this homework, lessons in class were not as exciting as poker. One of the very first tasks we had to learn was to write a program that calculated the factorial. For instance, five factorial, written as 5!, is equal to 5 times 4 times 3 times 2 times 1, or 120. Seeing how this was done by our human mind made me realize that the task could be done by going through a loop. Specifically, in this case, one goes through a multiplication loop five times, 5 X 4 X 3 X 2 X 1. Thus, what I needed was a register that got updated each time it went through the loop. That register must be initially equal to one.  In addition, I needed another number that started from the number whose factorial I am trying to solve and each time that number went through a loop, it must decrease by one and should continue to go through the loop until it equaled one.

The following is an example of a code that solves the factorial:


In the example above, the program actually starts with 1 then 2 then 3 then 4 then 5, but it achieves the same thing, at the end, fac becomes 1 times 2 times 3 times 4 times 5, which is 120 or 5 factorial.

The above example illustrates a function, a task that has been defined and can be interpreted by a computer. Thus, not everyone really needs to write from scratch. Not everyone needs to define every single task. As soon as a function has been defined, it can be called by another program. It can be used by another program or task. Thus, what my son or President Obama has written:

moveForward();

is really a predefined function or command, no different from the function factorial() shown above. 

With the specific examples shown above, I think we are then better equipped to address the question raised in the title of this post, Should We Teach All Children How to Code? 

Well, apparently, Matthew Murray at ExtremeTech has already attempted to answer such question so I am simply going to treat his article as a "function" and rerun it on this post. His answer to which I concur is as follows:
The subjects that should be strictly enforced as part of a K-12 curriculum in this country are the general-use ones that, for the most part, already are. Everyday mathematics, up to and including algebra. History and current events, both world and American. Surveys of biology, chemistry, and physics, for understanding how and why the world works. Civics, because knowing what the government should (and should not) do, and the citizen’s role in society, is key to adulthood. And, of course, English, and as much of it as possible, so students possess the elemental tools they need for communication. Within all these subjects there needs to be a focus on imagination, logic, reasoning, and problem solving — from which everything else in life will eventually come. The rest is gravy. Without these basics, being a terrific chef, a terrific carpenter, or even a terrific programmer, is meaningless. 
In 2010, USA Today reported statistics from the 2009 Programme for International Student Assessment that showed that “out of 34 countries, the US ranked 14th in reading, 17th in science, and 25th in math.” These are the problems we need to fix first. Once we do, and once our kids are competitive and commanding in these root areas, then and only then should we worry about whether programming needs to be given higher priority. Until then, and perhaps even after, helping kids understand what computers are, what computers are capable of, and where we can fit into the grand scheme of technology, is a good idea. Provided we still teach them how to make omelets and picture frames, too.





Comments