teaching programming: the importance of dry running …...teaching programming: the importance of...

39
Teaching Programming: The Importance of Dry Running Programs Paul Curzon Queen Mary University of London Please go now and register at http://bit.ly/CS4FN-DRYRUN Linked resources available at teachinglondoncomputing.org/dryrun/ Twitter @cs4fn 1

Upload: others

Post on 29-Sep-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Teaching Programming:The Importance of Dry

Running ProgramsPaul Curzon

Queen Mary University of London

Please go now and register at

http://bit.ly/CS4FN-DRYRUN

Linked resources available at teachinglondoncomputing.org/dryrun/

Twitter @cs4fn

1

Page 2: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

What do I mean by Dry Runs?• Acting as a ‘computer’

• in the original sense • of a human who is following an algorithm

• ‘Unplugged’ activities • away from a computer / compiler

• Working out in detail and step by step what a program does • on paper drawing tables • acting out computation / “compiling” on to

humans

2

Page 3: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Why are these activities vital?• Focus on semantics (meaning) not syntax (spelling)

• understanding what constructs do not just rote learning how to write them

• Develops logical thinking • Develops attention to detail • Allows teacher to quickly identify misconceptions

and faulty mental models • Helps students over barrier concepts • Transition step between explanations and programs

3

Page 4: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Ada - the first dry runner?• The claim that Ada

Lovelace was the first programmer arises not because of a program listing she wrote

• She created a dry run table for Babbage’s machine

• She pointed out a mistake in his algorithm as a result

4

Page 5: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Elf Computers

• Compile programs on to people • Act out the computation step by step • Why?

• GOOD WAY TO EXPLAIN SEMANTICS • see work on ‘semantic waves’

5

Page 6: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Let’s explore an example unplugged role play

dry run activity: Box Variables

6

Page 7: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Exercise• When I get to the role play… • You should work through the example at home

• Moving paper between boxes… • Or draw (a cartoon strip) of what happens

• COPYING THE ACTION!

7

Page 8: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

We are going to explore what a variable is and how they work

You will be able to:

• explain what a variable is

• work out what simple programs that manipulate variables do, step by step

8

Page 9: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

I’m going to use lego figures instead of people

• Variables are like storage boxes • Special ones that can

– Store – Create – Destroy

9

Page 10: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

What does this (python) code do?

colour1 = “red” colour2 = “green”

temp = colour1 colour1 = colour2 colour2 = temp

Let’s act it out (remember join in at home) !

10

Page 11: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

See the Box Variables Video teachinglondoncomputing.org/dryrun/

11

Page 12: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

In the google Doc…

http://bit.ly/CS4FN-DRYRUN

Write down as many facts about variables that we have just come across as you can

Exercise

12

Page 13: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Main points• A Variable is a storage space that holds data for later use

in a program • Variables have names

– so the computer knows which one is meant. • Variables hold values

– the actual data that is being stored. • Do not confuse variable names with their values!

• A variable can only store one value at a time. • When accessing a variable’s value you make a copy

– that variable’s value is untouched. • When you store a value in a variable you destroy anything

that was previously there.

13

Page 14: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Towards Dry Run Tables What does this program do?

Draw a series of pictures of boxes to find out… Draw the new state of the boxes with each line

a = 1

b = 2

b = a

a = b

a b

14

Page 15: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Dry Run tables

• This leads directly to the idea of dry run tables

• Combine the boxes into a table

a = 1 b = 2 b = a a = b

1

a b

15

Page 16: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Dry Run Tables: Example

• Let’s draw a table to see what this does:

a = 1 b = 2 b = a a = b

16

Page 17: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Dry Run Tables: Example

a = 1 b = 2 b = a a = b

1

a

17

Page 18: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Dry Run Tables: Example

a = 1 b = 2 b = a a = b

1

2

ba

18

Page 19: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Dry Run Tables: Example

a = 1 b = 2 b = a a = b

1

2

1

ba

19

Page 20: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Dry Run Tables: Example

a = 1 b = 2 b = a a = b

1

2

1

1

ba

20

Page 21: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Exercise: Your turn

• What does this code do? • Fill in this dry run table…

colour1 = “red” colour2 = “green” colour1 = colour2 colour2 = colour1

colour1 colour2

21

Page 22: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Solution

colour1 = “red” colour2 = “green” colour1 = colour2 colour2 = colour1

“red”

“green”

“green”

“green”

colour1 colour2

22

Page 23: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Diagnostic Tests

• A powerful way to detect (and correct) misconceptions early

• Set weekly dry run tests of (eg 5-12) short, critical dry runs

• Require table solutions • Mark immediately • Fix the mental models

of those making mistakes (immediately)

23

Page 24: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Now you do the diagnostic test… No marks if you do not fill out the tables!

You can download it from:

http://bit.ly/CS4FN-DRYRUN

Exercise

24

Page 25: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Fix the problems• Immediately sit down with anyone who got

most wrong • Do the first one in front of them

• (you may see the lightbulb appear above their head) • Get them to do one while you watch • Leave them to do the rest again

• Odd ones wrong - point out attention to detail matters.

• None wrong - praise their attention to detail

25

Page 26: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Dry Run tables are important

• Drawing tables matters (educationally) • Do NOT let students do it in their head. • Once you can program doing this is rare • BUT pedagogically it is a critical activity

• Programmers reason at a higher level of abstraction most of the time • writing tables gives a foundation for that

26

Page 27: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

If statements, loops etc

• The ideas extend to loops and if statements • When dry running:

• add an extra column for any test • Compile programs on to ‘Imp Computers’

• people represent instructions, • linked together by rope to represent the

control structure

27

Page 28: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

If statements, loops etc

a = 2 if a==3: b = 5 else b = 7

a2

b a==3?

2==3?false

7

• Add a column for each test • Add new rows for each time round a loop

28

Page 29: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

An Insulting Program

answer = input (“Shall I insult you?”)

if answer == “Y”: print (“You smell!”) else: print (“You smell of roses!”)

print (“Have a nice day”)

2929

Page 30: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

What it compiles to …

Each node is a student, connected by rope. You (the operating system) pass in a tube at one end. When it is handed back something should be printed on the screen (written on the board)

answer == “Y”?

Print “You smell!”

Print “Have a

nice day”

Print “You smell of roses!”

1

True

Falseanswer = input “Shall I insult you?”

30

Page 31: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Explaining programming concepts• We’ve made an invisible program

tangible • Can now explain all sorts of

concepts – If statements – Control structures – The program counter – Run-time versus compile time

• Similar approach for loops

3131

Page 32: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

More advanced concepts

1

• Can also explore more advanced ideas – How program changes change structure – Optimizing compilers – Bugs

32

Page 33: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

A Snap Program

card1 = input (“Next card”) card2 = input (“Next card”)

if card1 == “RED” and card2 == “RED”: print (“SNAP!”) else: if card1 == “BLACK” and card2 == “BLACK”: print (“SNAP!”)

print (“Bye”)

3333

Page 34: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

What it compiles to …

Each node is a student, connected by rope. You (the operating system) pass in a tube at one end. When it is handed back something should be printed on the screen (written on the board)

card1 == “BLK” & card2 == “BLK”?

Print “SNAP!”

Print “Bye”

Print “SNAP!”

1

True

False

card2 = input “Next card”

card1 = input “Next card”

False

card1 == “RED” & card2 == “RED”?

34

Page 35: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Exploring Different Programs

if card1 == “RED”: if card2 == “RED”: print (“SNAP!”) else: if card2 == BLACK: print (“SNAP!”)

3535

Page 36: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

What it compiles to …

Each node is a student, connected by rope. You (the operating system) pass in a tube at one end. When it is handed back something should be printed on the screen (written on the board)

card2 == “BLK”?

Print “SNAP!”

Print “SNAP!”

1

True

False False

card1 == “RED” ?

card2 == “RED” ?

False

True

True

36

Page 37: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Summary

• It is understanding semantics that matters when learning to program

• Unplugged Role play (‘Imp computers’) is a powerful first step

• Making students draw dry run tables is the next vital learning activity

37

Page 38: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Why are these activities vital?• Help in understanding what constructs do not just

rote learning how to write them • Develops logical thinking • Develops attention to detail • Allows teacher to quickly identify misconceptions

and faulty mental models • Helps students over barrier concepts • Transition step between explanations and

programs

38

Page 39: Teaching Programming: The Importance of Dry Running …...Teaching Programming: The Importance of Dry Running Programs Paul Curzon ... learning how to write them • Develops logical

Thank You

Resources at: teachinglondoncomputing.org/dryrun/

Twitter: @cs4fn

Please give feedback in the google doc

http://bit.ly/CS4FN-DRYRUN

39