# Tao of Computational Thinking in Programming

### Course Summary

The latest Word version (March 8th 2018) of this Course can be downloaded from:

taoword3.0

This is a Course in the pedagogy, and the computational thinking that underpins a creative problem solving approach to (learning) programming for Teachers of KS2/KS3+ pupils. The resources for the Course are freely available.
Selecting cross-curricula problem domains, which yield exciting, fertile problems for teachers and pupils to explore is axiomatic to our approach both in learning how to program and in developing the skills of programming.

For beginners, we start with the 2-D plane, using ‘human’ robots, paper and pencil, to derive many algorithms for human solutions to a simple linear grid problem. We express a human solution in a program of robot motion instructions directly related to the sprite/turtle instructions, using a set of commands bringing to bear the powerful programming concepts of  sequence, repetition and functions in English. We  transfer these English programs with same commands in abbreviated form to the ISPY,  push button, platform.

Later on, we extend our problem domain to the full 2D geometric plane  and create programs to draw intricate symmetrical geometrical patterns with polygons/stars/circles/spirals on the ISPY platform. The result: we are then able to transform a human solution into a program solution.

We are then in a position to map directly our instructions and programs into the more formal, rigorous and disciplined forms and processes necessary to drive the sprite in  the Scratch 2.0, or the turtle in the Python 3 programming environments, respectively.

Making the pedagogy explicit for teachers, and the computational thinking explicit for pupils in the process, is a fundamental underpinning in this Course delivery.

The Course is presently undergoing radical revision and rewriting. (You can copy this revision of the course as it is now, by viewing it in Google Chrome browser, with a right click, saving it as an html file to be viewed as a local file in your browser).

This is a work in progress. Your comments and suggestions are welcome.
If you want skip the Rationale, Overview, Pedagogy… and dive straight in to a problem, go with:

Let’s Go — Practical Sessions for Teachers — Project 1: The Aqado Board

Latest Update: 14th July 2017.

## Contents

Figure 2. —ISPY: Toolbox 2
Project 2 : Pixels: Setting up the symmetry of design by lining up repeated instructions

## Rationale

Our core approach is project-based,  problem-solving oriented and encourages creativity and computational thinking.
In this introductory part of the course we discuss with teachers a strategy of how to teach computational thinking and programming to pupils in the KS2/KS3 band, based on action research findings and classroom experience.
We assume in our approach that the pupils are new to text-based languages like Python. Our aim is to teach computational thinking in problem solving with unplugged programming on the way to learning Scratch 2.0 and/or Python 3 and we scaffold the learning of with the aid of  push-button ISPY, and later with Push-Python.

#### Using Unplugged Programming, Scratch 2.0 and Python 3

However, pupils who are already engaged with programming in Scratch can develop their computational thinking by undertaking the problems in the problem domain, while practising their use of sequence, repetition and functions in their Scratch.  Similarly, with learners of Python 3. If you want a more interactive hands-on programming process with instant incremental response, use ISPY and later Push-Python. Pupils who are conversant with Scratch 2.0 can undertake the projects with Scratch as their programming language and use ISPY and Push-Python as a transition vehicle to scaffold their introduction to Python 3 when the time is right. Our general approach can be summarised as:

1. Develop an ongoing pedagogy in computing (ispython.com/pedagogy) guided by: a project-based problem-solving approach, current research findings, classroom experience, existing expertise in other disciplines. And  we look to take part in further action-research in the classroom.
2. Select a cross-curricula problem domain, interesting and responsive, fun for pupils to explore, and fertile in problems to solve
3. Examples.  Choose a do-able  project to undertake. Use graded and related example problems (decomposition) first for practice, and so build confidence before taking on the project.
4. Choose a basic appropriate programming toolbox in which to design and create user-tools for problem solving in this domain.
5. Implement the simple, but general, paradigm for problem solving in computing:                                                                  program(toolbox + user-created tools) = solutions
6. Harness computational thinking in problem-solving to achieve a human solution in pursuit of a program solution.

### Overview: Teaching at the KS2/KS3 Interface for beginners in Scratch 2.0 and/orPython 3

Here our strategy is to recognise that we are embarking on a path to teach beginners computational thinking in programming. The pedagogy we employ, choice of problem domain, examples, programming toolbox, programming paradigm and computational thinking are geared to delivering the start of a pathway, which is suitable for teaching beginners in the KS2/KS3 spectrum.

#### 1. Pedagogy for beginners in Computational Thinking and Python 3

Our pedagogy, which we try to make explicit in the process of delivery for teachers, for this project includes:

• Investigating human solutions with pencil and paper
• Unplugged programming: human robot ‘Walking the Talk’ solutions
• Enquiry-led learning
• Read code before you write code
• Opportunities for experimenting and learning by doing
• Guidance in graded problems to promote computational thinking in programming
• Looking at different solutions (generalising and evaluating)
• Transferring our drawing/walking solutions and our robot to the screen with
1.  ISPY (red arrow) – push-button, instant response, scaffolded programming for beginners
2. Scratch 2.0 (sprite)
3. Python 3 (turtle)
• Inhabiting  a drawing  environment,  in which the project and related problems have an ongoing graphical response with which to gauge progress. (The response is instant when using ISPY and Push-Python.)
• Selecting a project and adopting a problem-solving approach to learning computational thinking and programming
• Investigating human solutions with pencil and paper
• Unplugged programming:  with the ‘human’ robot ‘Walking the Talk’  programming solutions
• Practising with simpler but  related problems
• Enquiry-led learning
• Reading  code before you write code (on ISPY)
• Opportunities for experimenting, using and creating tools, and learning by doing
• Guidance in graded problems to promote computational thinking in programming
• Looking at different solutions (generalising and evaluating)
• Transferring our drawing/walking solutions, and our robot solutions,  for further development to the screen with

#### 2. Problem Domain: Grid of Squares in the 2-D plane

Figure 3. Flying red-arrow on a square grid: symmetry and repetition in the drawing — reflected in the code.

We have chosen a 2-D rectilinear grid as our first problem domain. The advantages of this and the  2-D open plane as a follow-up domain are:

• that the developing programming produces an immediate response, whether that is:
• Drawing on paper
• “Walking the talk” — motion with a ‘human’ robot
• Flying red-arrow using ISPY on screen. See Figure 3 and Session 4).
• There is a direct correlation between the three positional movements: forward, left turn and right turn of the unplugged human robot, the activities listed above, and the motions of the Scratch sprite and the Python turtle, all of which inform the transition from KS2 to KS3, unplugged to block-based to text-based programming.
• Consequently, you can move to ISPY, Scratch 2.0, Python 3 now, or at any point in this Course. We think there is much to be gained by first focussing on and gaining competence in the computational thinking in human problem solving by devising an ‘unplugged’ program of drawing/walking the robot, and/or an ‘unplugged’ program to move the red arrow in ISPY by pushing buttons. The pupils’ ‘unplugged’ programs, which will employ the basic ‘motion’ instructions of a robot/sprite/turtle and the programming concepts of sequence, repetition and functions are straightforwardly mapped into Scratch 2.0 and Python 3. The additional challenge of the learning in detail required to familiarise pupils with a block-based or text-based programming environment can then be undertaken to implement the ‘unplugged’ program solutions in Scratch/Python. An introduction to Scratch 2.0 geared to this course can be downloaded from repository-2.
• Symmetry and pattern in drawings can be used in computational thinking to link the corresponding symmetry and pattern in the code and vice-versa, via the programming control structures of sequence, repetition and functions.
• Using the instructions: ` fd1, lt, rt ` what is the code for this staircase?
``` fd1 lt fd1 rt fd1 lt fd1 rt fd1 lt fd1 rt``` …………… UPL(1)
• but see Session 3… “Introducing Repetition…”  for more concrete discussion]

#### 3. Project 1: Drawing the Board for the Game Aqado

Figure 4. The board for the game Aquado. (AQA GCSE controlled assessment 2015)

The specific project we start with: build a program to draw the Aqado game board in Figure 4. Aqado is a counter game played with a dice to be hosted on a computer(part of an AQA GCSE 2015 controlled assessment assignment).

The project could, of course, be to draw any one of a number of grid board games, including noughts and crosses 3×3, boggle 4×4, 5×5, draughts 8×8, sudoku 9×9, snakes and ladders 10×10, crosswords 13×13, …

In order to pave the way to complete Project 1, we engage with a number of simpler related problems.(Decomposition).

#### 4. Programming Toolbox

The 3 basic motion instructions for line drawing in Figure 5, with Seymour Papert’s turtle (in Python) or the Scratch sprite, together with 3 programming control structures: sequence, repetition and functions make up our starting programming toolbox. Useful tools for drawing are created from the basic toolbox to solve specific problems and added as new instructions to our toolbox.

#### 5. Programming Paradigm

Implement the simple, but general, paradigm for problem solving in computing:

programmming(toolbox + user-created tools) = solutions.

We add user-designed tools to the toolbox, by defining equivalent code functions derived from the component instructions in the basic toolbox. The objective is for pupils to learn how to use user-designed tools and then to design their own simple tools; and adopt this programming paradigm for more effective problem solving.

#### 6. Model of Computational Thinking

Our approach encourages creativity through symmetry and pattern matching.

• Algorithmic Thinking – thinking through the strategy and steps required to solve a problem(AT)
• Decomposition and Synthesis – breaking a problem down into its smaller components(D) and putting the components together
• Abstraction – reducing and hiding complexity by using or creating tools/models
• Generalization — adapting solutions so that they can be used to solve a wider range of problems(G)
• Evaluation – assessing whether a program or technique works correctly, efficiently and by other criteria e.g. maintains good programming practice.(E)

## Let’s Go: Practical Sessions for Teachers — Project 1: The Aqado Board

In this example, we give instructions for the class (preceded by  •) and add comment (in italics) to make explicit  some of the computational thinking and pedagogy that underpins the sessions.

#### Session 1: Computational Thinking for a Human Solution

Figure 6 .

We are going to look at solutions to a simpler problem than the Aqado board. (Decomposition: we simplify the problem, by choosing a model that picks out the bare essentials of the line drawing: a basic 3×3 grid of squares — hiding a lot of the detail and structure of the project. (Abstraction). And our simple model also forms the basis for projects involving any number of different board games.

• Show the Aqado board and the reduced model in Figure .
• Give out paper and pencil. Ask each person to draw just the 3×3 grid model.
• Ask them to describe how they did it — their algorithm for a human solution.  (Algorithmic Thinking)
• Draw their attention to the symmetry in the 3×3 grid and the components that make up the grid. Ask them to draw the 3×3 grid again ‘systematically’, to bear in mind that they might want to draw a 4×4 or a 10×10 grid later on…(Generalisation)
• In small groups, ask them to discuss and come up with 3 or 4 really different ways to draw the 3×3 grid. There are at least a dozen different ways…
• If necessary, give them a hint: What do you see in the model as potential building blocks/templates to repeat in order to draw the model ‘systematically’. [ lines, squares and rectangles…]
• Ask them to choose one solution they can use to build a program which seems easiest — perhaps easiest to generalise. (Evaluation)

#### Our ‘Unplugged’ Programming Tool box:

• Describe ‘Walking the Talk’ with the 3 instructions, in UPL (unplugged programming language): `forward, left turn, and right turn` to drive the robot. These instructions are common to Scratch, Python, (and other languages which implement the sprite/turtle). Together with the universal programming control structures of sequence, repetition and functions. The toolbox can be expanded (later) by introducing user-defined functions/instructions representing building blocks e.g. squares, lines, or rectangles.
• Find out if everybody knows what characterises a robot/sprite/turtle/ in the plane when we want it to move? (Enquiry-led learning). [Answer: position, direction]
• Ask everybody (who agrees to) to stand up and be a robot.
• Describe how at the start, a robot faces to the right as the handler views them, and chooses enough space in front and to their left to allow at least one pace forward or to the left. (If you think of the floor as a page, on which they leave a trail — a drawing, each robot is standing at the bottom of the page and the top of the page is to their left). See Figure 3.

#### Repetition and Return Programs

• Get all the robots moving.See ‘Walking the talk’ and ISPY in action. Give the following commands verbally. (To illustrate the repetition with your voice — pause after each line):
```forward one, left turn forward one, left turn forward one, left turn forward one, ``` …………………………UPL(2)
• Ask them to describe what happened, and what they have drawn.
• What would be the effect of adding another instruction: `left turn` in the last line of the example?

Figure 7 (a),(b)Two programs for a square — one symmetric (b)– a returned program.

The same program in the UPL short code, (and on the push buttons in ISPY) would be:

```fd1 lt fd1 lt fd1 lt fd1 ``` ………………UPL(3)

We are looking for repetition and symmetry together in the shape drawn, and in the code. The complete code symmetry is finally achieved by adding the lt command on the final line in program UPL(2). An example of a  return  program. (One where the robot returns to the starting position and starting direction).
Note the symmetrical code for the square consisting of 4 repeated lines of code for a return program:

```fd1 lt fd1 lt fd1 lt fd1 lt ``` ………………UPL(4)

We shall pick up on symmetry and repetition of code in programming again in Session 3.

#### Session 2: Computational Thinking for a Computer Solution

It would be possible now, with our 3 instruction toolbox to instruct the  robot to draw the 3×3 grid.  We could try for a computer solution to mimic a human drawing solution ?
Here is one solution:

pseudocode:

1. draw a 3×3 square
2. move the robot to point A facing right
3. draw a 3×1 rectangle
4. move the robot to point B facing up
5. draw a 3×1 rectangle

3×3 square with points A, B

‘unplugged’ program
1 `fd3 lt fd3 lt fd3 lt fd3 lt`
2 `lt fd1 rt`
3 `fd3 lt fd1 lt   fd3 lt fd1 lt`
4 `rt fd1 lt fd2 lt`
5 ```fd3 lt fd1 lt   fd3 lt fd1 lt 6 lt fd2 lt lt ...............UPL(5) ```

Completed 3×3 grid: 3×3 square and two 3×1 rectangles

#### Mimicking the Human Solution?

We could get the computer to mimic the human solution exactly? Or we can try to harness directly the properties and capacities of our toolbox, by experimenting with the instructions and introducing ‘verbally’ our programming toolbox in its ‘unplugged’ format, including the programming control structures sequence, repetition and functions.

#### Session 3: Functions and User-designed Tools

The instructions `left turn` (or shortly: `lt`); `right turn: rt` are functions. They stand for fairly complex code (machine code) which is hidden (abstraction). (There is no number (argument) attached to these instructions; the turn is through 90 degrees, understood –- this changes later when we move from the grid to an extended problem area: the whole 2-D plane).

The instruction `forward, fd ` is accompanied by an argument, a number, so `forward3` or `fd3` is move forward 3 paces and draw as you go, — again a function this time with a number (argument) — the number of paces — 3. We will be creating and using tools, user-defined functions, which use arguments just like the  instruction ` forward`  does. For example, a user tool to draw a square with a side length of say,  2 paces we might create as  square2 or shortly sq2, where the two could be replaced by whatever number we choose.

Figure 8.(a) Drawing capital L
(b) Drawing capital L as a return program

• Get the participants to inhabit the robot/handler relationship by working in pairs to understand and practise the three moves. For example, by drawing a capital letter from an easy-to-draw  set: ‘L’, ‘I’, ‘F’, ‘T’, ‘E’, ‘P’ or other shapes: rectangles, squares, ‘+’, ‘9’…
The code for capital L, with the robot starting from bottom left and facing right, could be:
``` forward one, left turn, left turn forward one, right turn, forward two```……..UPL(6)
The return program in Figure (b) is achieved by adding the instructions
` left turn, left turn, forward two, left turn`
to the end of the previous code (A return program is one which finishes with the robot, sprite or turtle finishing at the starting point and pointing in the starting direction)
• Draw a rectangle using a return program. Thus illustrating how the symmetry of the drawing is reflected in the code

Figure 9. A 3×1 rectangle

[Ans: The code for a 3×1 rectangle could be:
```forward three, left turn, forward one, left turn forward three, left turn, forward one, left turn```……..UPL(7)
or in the short code version:

```fd3 lt fd1 lt fd3 lt fd1 lt```……..UPL(8)]

When there is a repeat symmetry in the code it is useful to pick this out by lining the code up with repeats on consecutive lines, see UPL (1),(2),(3),(5),(6),(7),(8) — in preparation for using the repetition structure in the programming language.The return program often helps to complete symmetry in the code, but it is also an important concept when later we want to create patterns.

#### Introducing Repetition and Functions with the ‘Human’ Robot

Sequence, Repetition and Functions in Unplugged Programming

Programming languages contain repeat structures. So we ask our intelligent robots to recognise their ‘wired in’ repeat ability.

Give the command (with intonation to insert the brackets!):

repeat 4[fd1 lt]………………………………UPL(9)

and watch them obey.

Then call upon their ‘wired in’ understanding of functions and name the code square1 or sq1 (for short when we go to the screen), a function with a parameter ‘pace’, which could be 2, 3 … paces along a side of a grid, in a similar vein to the function forward1, 2, 3… paces. (In unplugged programming, we define a user function by the code we name but, helpfully, not yet with a formal syntax definition for the function or its parameter). Again it is essential to note that when we issue a command (instruction/user function) that it gets the robot to act from its present location and direction.

{** this more formal notation we introduce in later sessions. We can define and use our user functions in unplugged programming without it.

More formally, we use ‘–>’ as our symbol for ‘defining’ a function with a parameter p by writing:

squarep or sqp –> repeat 4[fdp lt]………………………………UPL(10)

Where p can take values (arguments) 1, 2, 3… **}

Give the command:  square2. (See Figure 5 below for same command in ISPY). Note that every command that we give to the human robot, is available at the screen with ISPY.(Figure 5.)

(For robot practice, divide into pairs, handler and robot, and the handler uses instructions to the robot partner to draw some capital letters: e.g. I, L, F, E, T, P or combinations of square and write down the corresponding return programs. The handler can, in each case,

1. build the code for the letter from the three instructions,
2. by taking note of symmetry in the drawing, use the repeat control structure in the program,
3. by identifying building blocks for the drawing, include user-defined functions in the program.

Examples: For Figure 4(e) L the code might be:

fd1 lt lt fd1 rt fd2………………………UPL(11)

or as a return program

fd1 lt lt fd1 rt fd2   lt lt fd2 lt……………………………UPL(12)

and for Figure 4(f) F the code might be

lt repeat 2[fd1 rt fd1 lt lt fd1 rt]……..………………UPL(13)

or as a return program

lt repeat 2[fd1 rt fd1 lt lt fd1 rt] lt lt fd1 lt fd2 lt………UPL(14)

and for Figure 4(g) P the code might be (note the use of user-function sq1)

lt fd1 rt sq1………………………………………………………………………………………UPL(15)

or as a return program

lt fd1 rt sq1   rt fd1 lt.……………………………………………………UPL(16)

The above code introduces and illustrates our programming paradigm

program(toolbox + user-created  tools) = solutions

by making use of:

• the toolbox instructions fd, lt and rt
• repeat programming control structure
• functions: user-defined function like sq (because the instruction sq or square is not already defined as an instruction in the repertoire of the sprite or turtle, and it is useful to us in our proposed solutions)

(E.g each capital letter could then be named as a user-defined function).

Try the remainder of the examples in Figure 4, identifying symmetry and building blocks in the drawings to use repeat and user-defined functions in the programs.

We can define two more building blocks as user-defined functions: a (return) line and a (return) rectangle to help us with alternative solutions for the 3×3 grid:

fetchp (fep) –> fdp lt lt fdp lt lt………………………………………UPL(17)

rectanglep (rep) –> repeat 2 [fdp lt fd1 lt]………………UPL(18)

(a rectangle is here defined to have a variable length parameter: p paces, and a fixed breadth of 1 pace).

For  letter E, the code might be

fe1 repeat 2[lt fd1 rt fe1]……………………………………………………………UPL(19)

These are more examples of user-defined functions — the building blocks identified in the discussed solutions. This illustrates the problem solving paradigm: Choose your toolbox for the problem, and create more tools (functions) to represent the physical building blocks for your drawings as you need them.

Results: Teacher devised solutions of 3×3 model written after ’Walking the talk’:

 Solution 1: fe3 repeat 3[lt fd1 rt fe3] rt repeat 3[lt fd1 rt fe3] Solution 2: sq3 repeat 2[fd1 lt fe3 rt] fd1 lt repeat 2[fd1 lt fe3 rt]

 Solution 3: repeat 3[re3 lt fd1 rt]         rt                              repeat 3[re3 lt fd1 rt] fd3 rt fd3 lt lt Solution 4: repeat 3[re3 lt fd1 rt] fd1 rt re3 rt fd1 lt fd3 lt Solution 5 repeat 2[sq1 sq2 sq3 fd3 lt        fd3 lt] Solution 6: rowsq –> repeat 3[sq1 fd1]     repeat 4[rowsq lt]

Solution 5 uses some duplication in that it redraws lines already drawn, but the program is short and elegant. Does it generalise?

Solution 6 defines a function for a row of squares rowsq using an existing user-function sq. Clever and works for 3×3. Not easily generalizable. How would you adapt rowsq to write a program that was easier to generalise? (Return program?) How many of 1-6 are return programs? (Plenty more solutions! Lots of discussion, but all teachers agreed they could build the programs in UPL, Scratch or Python.)

Graded Challenges: Why would you draw a grid? Board Games challenges in UPL (ISPY) include: 3×3 Noughts and Crosses; 4×4, 5×5, 6×6 Boggle (a spelling game on the grid); 6×6 Conway’s Game of Life; 7×7 Othello;  8×8 Chess and Draughts; 9×9 Sudoku; 10×10 Snakes and Ladders; 11×5 Aqado; 13×13 crosswords. Other contenders: Ludo, Monopoly, Scrabble, Go, Connect 4.  Project 2 Pixels and Colour backgrounds, National flags, Bar scarves, Pixel pictures …

Further Challenges to come: move on to challenges in the open 2-D plane: polygons, stars, circles, curves, spirals, patterns, linear transformations:  translation, rotation, reflection; action geometry, transitional geometry. Solar system and planetary motion. Move on to graded missions in unplugged programming in ISPY and Push-Python (when live!):

ispython.com/ispy

All these problems are programming tasks and could be solved in Scratch 2, or Python 3, but ISPY has a version with an integrated graded problem set, and in all versions is incrementally interactive with no syntax errors, and no ‘save and run’ procedure and a delete button for semantic or logical errors, ideal as a transition phase and for learning Python 3. See Figure 5. If you want to carry on with problem solving on the grids without tackling a programming environment using the basic toolbox with repeat and user defined functions in a push-button environment then download ISPY1. Move on to ISPY2 when you want to introduce defining and using user functions and colour.

Otherwise you can proceed with the sprite of Scratch 2.0 or the turtle in Python 3. To help bridge that transition, we include at the end of this section Scratch 2.0  and Python 3 solutions for solution 4 above.

to be continued…

#### Session 4: Moving to the Screen with ISPY

to be continued…(we intend an improved beta version of the software for ISPY to be available for download for free day courses at UCL for teachers for Summer School 2017)

Figure . ISPY — Toolbox1
Picking up the symmetry in the rectangle 3×1 using a repeat instruction

to be continued…