# A journey from Computational Thinking to Programming

A computer does two things, and two things only. It performs calculations and it remembers the results of those calculations. But it does those two things extremely well. The typical computer that sits on a desk or in a briefcase performs a billion or so calculations a second.

For most of human history, computation was limited by the speed of calculation of the human brain and the ability to record computational results with the human hand. To solve the problem with the computer we should be comfortable with computational thinking.

**What do we mean by computational thinking? **All knowledge can be thought of as either declarative or imperative.

**Declarative Knowledge**

Declarative knowledge is composed of statements of fact. For example,

**“The square root of \(x\) is a number \(y\) such that \(y*y = x\).”**

This is a statement of fact. Unfortunately it doesn’t tell us how to find a square root.

**Imperative Knowledge**

Imperative knowledge is “how to” knowledge, or recipes for deducing information. **For Example** To calculate the square root of any number \(x\) is:

- Start with a guess, \(g\).
- If \(g*g\) is close enough to \(x\), stop and say that \(g\) is the answer.
- Otherwise create a new guess by averaging \(g\) and \(\frac{x}{g}\), i.e., \(\frac{(g + \frac{x}{g})}{2}\).
- Using this new guess, which we again call \(g\), repeat the process until \(g*g\) is close enough to \(x\).

Note that the description of the method is a sequence of simple steps, together with a flow of control that specifies when each step is to be executed. Such a description is called an algorithm.

A bit more formally, **an algorithm is a finite list of instructions that describe a computation that when executed on a provided set of inputs will proceed through a set of well-defined states and eventually produce an output. **An algorithm is a bit like a recipe from a cookbook.

**So how does one capture this idea of a recipe in a mechanical process?**

One way would be to design a machine specifically intended to compute square roots. Odd as this may sound, the earliest computing machines were, in fact, **fixed program computers**, meaning they were designed to do very specific things, and were mostly tools to solve a specific mathematical problem, e.g., to compute the trajectory of an artillery shell. One of the first computers (built in 1941 by Atanasoff and Berry) solved systems of linear equations, but could do nothing else. Alan Turing’s bomb machine, developed during World War II, was designed strictly for the purpose of breaking German Enigma codes. Some very simple computers still use this approach.

Other way is **stored-program computer**. Such a computer stores (and manipulates) a sequence of instructions, and has a set of elements that will execute any instruction in that sequence. By creating an instruction-set architecture and detailing the computation as a sequence of instructions (i.e., a program), we make a highly flexible machine.

By treating those instructions in the same way as data, a stored-program machine can easily change the program, and can do so under program control. Indeed, the heart of the computer then becomes a program (called an interpreter) that can execute any legal set of instructions, and thus can be used to compute anything that one can describe using some basic set of instructions.

Both the program and the data it manipulates reside in memory. Typically there is a program counter that points to a particular location in memory, and computation starts by executing the instruction at that point. Most often, the interpreter simply goes to the next instruction in the sequence, but not always.

In some cases, it performs a test, and on the basis of that test, execution may jump to some other point in the sequence of instructions. This is called flow of control, and is essential to allowing us to write programs that perform complex tasks.

Returning to the recipe metaphor, given a fixed set of ingredients a good chef can make an unbounded number of tasty dishes by combining them in different ways. Similarly, given a small fixed set of primitive elements a good programmer can produce an unbounded number of useful programs. This is what makes programming such an amazing endeavor.

To create recipes, or sequences of instructions, we need a **programming language** in which to describe these things, a way to give the computer its marching orders.

This article is contributed by Ram Kripal. If you like eLgo Academy and would like to contribute, you can mail your article to admin@elgoacademy.org. See your article appearing on the eLgo Academy page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.