teaching programming: the importance of dry running …...teaching programming: the importance of...
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/1.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/2.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/3.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/4.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/5.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/6.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/7.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/8.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/9.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/10.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/11.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/12.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/13.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/14.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/15.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/16.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/17.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/18.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/19.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/20.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/21.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/22.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/23.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/24.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/25.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/26.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/27.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/28.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/29.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/30.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/31.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/32.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/33.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/34.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/35.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/36.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/37.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/38.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022052005/6018869ce66fd256ca7706bf/html5/thumbnails/39.jpg)
Thank You
Resources at: teachinglondoncomputing.org/dryrun/
Twitter: @cs4fn
Please give feedback in the google doc
http://bit.ly/CS4FN-DRYRUN
39