Strategies for teaching programming Sue Sentance King’s College London @suesentance [email protected] CAS South East Conference 6 th July 2017
Strategies for teaching programmingSue Sentance
King’s College London
@suesentance
CAS South East Conference
6th July 2017
As you come in…
Can you spot the errors in this Python 3 program:
What I hope to cover today…
Why programming can be difficult
What research tells us (briefly)
What teachers tell us
Pair programming
Peer instruction activity
Code tracing activity
Use-modify-create
Predict-explain-modify-create
Why programming can be difficult
Students may not have an accurate mental model of the process/computer
Is the computer doing some kind of magic? The trial and error / fingers crossed approach
Syntax errors knock confidence
Programs don’t work more often than they do work
Multiple skills/understanding of concepts/mechanisms compressed into one line of code
Difficulty with thinking algorithmically
Working at different levels of abstraction
Threshold concepts and misconceptions
?
As teachers can we relate to any of these?
Why programming can be difficult
Students may not have an accurate mental model of the process/computer
Is the computer doing some kind of magic? The trial and error / fingers crossed approach
Syntax errors knock confidence
Programs don’t work more often than they do work
Multiple skills/understanding of concepts/mechanisms compressed into one line of code
Difficulty with thinking algorithmically
Working at different levels of abstraction
Threshold concepts and misconceptions
?Conceptual difficulties
Why programming can be difficult
Students may not have an accurate mental model of the process/computer
Is the computer doing some kind of magic? The trial and error / fingers crossed approach
Syntax errors knock confidence
Programs don’t work more often than they do work
Multiple skills/understanding of concepts/mechanisms compressed into one line of code
Difficulty with thinking algorithmically
Working at different levels of abstraction
Threshold concepts and misconceptions
?The process of programming
Block-based and frame-based tools offer support
Scratch
Patch
Stride
Stride
But what about a blank Idle window?
(or equivalent in your favourite text-based language?)
Ever not been sure
where to start?
What research tells us about learning programming
1. Read before you write – there is clear evidence that tracing and explaining code helps (Lister, numerous
papers)
2. Levels of abstraction - problem at higher-level; syntax at lower-level (Perrenet & Kassenbrod, 2006)
3. Threshold concepts in programming cause difficulties for students (Sanders & McCartney, 2016)
4. Misconceptions abound (research from 1980s to current day – Juha Sorva)
5. Pair programming and peer instruction help – these suggest that dialogue and discussion at a logical
level help students (Porter et al, 2012)
6. Growth mindset – popular approach, with some research evidence in Computing (Cutts, 2010)
Pair programming – supporting learning of programming
Pair programming started off in industry.
Now there is good evidence that pair programming
works in university settings, for example in introductory
programming classes
Good for girls
Another article by Linda Werner et al suggests
it supports engagement by girls/women
Use in school
Now starting to see evidence from research in
school (e.g. Werner, L., & Denning, J. (2009).
Pair programming in middle school: What
does it look like?. Journal of Research on
Technology in Education, 42(1), 29-49.
Talking about your program:
…the process of expressing a problem verbally helps
the programmer to develop their own understanding
and can often lead to a solution.(Wray, 2010)
If you only do ONE thing …. try pair programming
Activity : Peer instruction
You will need some A, B, C, D cards
Look around you because you will be discussing in groups of 3
We will do the activity first then reflect on the process
Peer instruction
Well-evidenced pedagogical strategy
Combination of:
- Flipped learning
- Collaborative working
- Well-chosen MCQs
Process
- Step 0: Study topic before session
- Step 1: MCQ question presented to class
- Step 2: Individually decide on answer
- Step 3: All vote
- Step 4: Discuss answer as group
- Step 5: Group decides on answer
- Step 6: All groups vote
- Step 7: Discuss as class
For more information see
http://peerinstruction4cs.org
Example 1
The variables angel and egyptian contain 1.7 and 2.0 respectively, which represent
their height.
What is written out…?
IF angel > egyptian THEN
SEND "Egyptian is taller" TO DISPLAY
ELSE
SEND "Angel is taller" TO DISPLAY
END IF
A. Egyptian is taller
B. Angel is taller
C. Egyptian is taller Angel is taller
D. <nothing is output>
14
Example 2
Consider what this code does when metalColour is blue, red, or green…
IF metalColour == "blue" THEN
SEND "Cold" TO DISPLAY
ELSE IF metalColour == "red" THEN
SEND "Hot!" TO DISPLAY
ELSE
SEND "Try again!" TO DISPLAY
END IF
END IF
Which options are true?
A. When metalColour is blue, Cold displayed
B. When metalColour is red, Hot! displayed
C. When metalColour is blue, both Cold AND Try again!
displayed
D. When metalColour is green, nothing happens 15
Example 3
How many times is Hello written out?
SET i TO 0
WHILE i <= 5 DO
SEND "Hello" TO DISPLAY
SET i TO i + 1
END WHILE
A: 4
B: 5
C: 6
D: 7
E: <other> 16
Example 4
Peer Instruction – testing for faulty mental models
• Technique originally developed in Physics by Eric Mazur at Harvard university
• Way of assessing whether novices really understand concepts requiring a precise
understanding
• Based on carefully designed multiple choice questions with structured discussion and voting
17
Peer instruction in a school context
Before
Pupils have worked with the concepts in class or at home.
Individual
•Pupils read the question and choose an answer
•Vote takes place
Group
•Pupils discuss what answer they chose and why
•Vote takes place
Class
•Teacher facilitated discussion
•Vote takes place
Correct Answer
•Teacher reveals the correct answer
•Teacher explains why it’s correct
18
Peer instruction vs teacher explanation: research findings
Statistically
significant
effect
Twice as effective
as a good teacher
explanation
Successfully used in
Physics, Maths and
Computing Science Develops better sense
of self efficacy
particular amongst
girls
19
What other teachers have told us
Key strategies for teaching Computing
- Unplugged activities
- Relate to the real world
- Work with problems
- Work together
- Practical/hands-on exercises
… And particularly for programming
- Scaffolding programming tasks
- Exercises manipulating/modifying code
- Use examples
- Pair programming
From Computing in the curriculum: challenges and strategies from a teacher’s perspective
Another activity: Tracing code
Variables Table Input
Output
a = 9
b = 7
b = a
print b
a = 10
print b
Step 1- Draw a red rectangle around all expressions
Expression evaluator
Variables Table Input
Output
a = 9
b = 7
b = a
print b
a = 10
print b
Step 2- Draw in the flow of control as arrows in blue
Expression evaluator
Variables Table Input
Output
a = 9
b = 7
b = a
print b
a = 10
print b
Step 3- Hand execute the program
Expression evaluator
a
1. 9
Variables Table Input
Output
a = 9
b = 7
b = a
print b
a = 10
print b
Step 3- Hand execute the program
Expression evaluator
1
a b
1. 9 2. 7
Variables Table Input
Output
a = 9
b = 7
b = a
print b
a = 10
print b
Step 3- Hand execute the program
Expression evaluator
1
2
a b
1. 9 (3) 2. 7
3. 9
Variables Table Input
Output
a = 9
b = 7
b = a
print b
a = 10
print b
Step 3- Hand execute the program
3 a
9
Expression evaluator
1
2
3
a b
1. 9 (3) 2. 7
3. 9 (4)
Variables Table Input
4. 9
Output
a = 9
b = 7
b = a
print b
a = 10
print b
Step 3- Hand execute the program
3. a
9
4. b
9
Expression evaluator
1
2
3
4
a b
1. 9 (3) 2. 7
5. 10 3. 9 (4)
Variables Table Input
4. 9
Output
a = 9
b = 7
b = a
print b
a = 10
print b
Step 3- Hand execute the program
3. a
9
4. b
9
Expression evaluator
1
2
3
4
5
a b
1. 9 (3) 2. 7
5. 10 3. 9 (4,6)
Variables Table Input
4. 96. 9
Output
a = 9
b = 7
b = a
print b
a = 10
print b
Step 3- Hand execute the program
3. a
9
4. b
9
6. b
9
Expression evaluator
1
2
3
4
5
6
Now you try:
Take a handout and a partner
The following example has been adapted from the TRACS system developed by CAS Scotland
(I have called it Mini TRACS)
Variables Table
What is printed?
counter = 1
while counter < 4:
print("Happy days")
counter = counter + 1
print(“End of program”)
Variables Table
What is printed?
counter = 1
while counter < 4:
print("Happy days")
counter = counter + 1
print(“End of program”)
Step 1: Draw round all expressions
Variables Table
What is printed?
counter = 1
while counter < 4:
print("Happy days")
counter = counter + 1
print(“End of program”)
Step 2: Draw arrows to show the order the statements are executed
FALSE
TRUE
Variables Table
What is printed?
counter = 1
while counter < 4:
print("Happy days")
counter = counter + 1
print(“End of program”)
Step 3: Work through the program showing variables and output
FALSE
TRUE
counter
Variables Table
What is printed?
counter = 1
while counter < 4:
print("Happy days")
counter = counter + 1
print(“End of program”)
Step 3: Work through the program showing variables and output
FALSE
TRUE
1
counter
Variables Table
What is printed?
counter = 1
while counter < 4:
print("Happy days")
counter = counter + 1
print(“End of program”)
Step 3: Work through the program showing variables and output
FALSE
TRUE
1
counter
1 TRUE
Variables Table
What is printed?
counter = 1
while counter < 4:
print("Happy days")
counter = counter + 1
print(“End of program”)
Step 3: Work through the program showing variables and output
FALSE
TRUE
1
counter
1
counter
Happy days
2
Working out areacounter = counter + 1counter = 1 + 1counter = 2
Variables Table
What is printed?
counter = 1
while counter < 4:
print("Happy days")
counter = counter + 1
print(“End of program”)
Step 3: Work through the program showing variables and output
FALSE
TRUE
1
counter
2 TRUE 2
Happy days
Variables Table
What is printed?
counter = 1
while counter < 4:
print("Happy days")
counter = counter + 1
print(“End of program”)
Step 3: Work through the program showing variables and output
FALSE
TRUE
1
counter
1
counter
Happy days
2
Happy days
3
Working out areacounter = counter + 1counter = 2 + 1counter = 3
Variables Table
What is printed?
counter = 1
while counter < 4:
print("Happy days")
counter = counter + 1
print(“End of program”)
Step 3: Work through the program showing variables and output
FALSE
TRUE
1
counter
3 TRUE 2
3
Happy days
Happy days
Variables Table
What is printed?
counter = 1
while counter < 4:
print("Happy days")
counter = counter + 1
print(“End of program”)
Step 3: Work through the program showing variables and output
FALSE
TRUE
1
counter
1
counter
Happy days
2
Happy days
3
4
Happy days
Working out areacounter = counter + 1counter = 3 + 1counter = 4
Variables Table
What is printed?
counter = 1
while counter < 4:
print("Happy days")
counter = counter + 1
print(“End of program”)
Step 3: Work through the program showing variables and output
FALSE
TRUE
4 FALSE1
counter
1
counter
2
3
4
Happy days
Happy days
Happy days
Variables Table
What is printed?
counter = 1
while counter < 4:
print("Happy days")
counter = counter + 1
print(“End of program”)
Step 3: Work through the program showing variables and output
FALSE
TRUE
1
counter
1
counter
Happy days
2
Happy days
3
4
Happy days
End of program
FALSE
Now for another example
Variables Table
SET total TO 0
RECEIVE nextInput FROM (INTEGER) KEYBOARD
WHILE nextInput != -1 DO
SET total TO total + nextInput
RECEIVE nextInput FROM (INTEGER) KEYBOARD
END WHILE
SEND total TO DISPLAY
Step 1- Draw a red rectangle around all expressions
Expression evaluator
Variables Table
SET total TO 0
RECEIVE nextInput FROM (INTEGER) KEYBOARD
WHILE nextInput != -1 DO
SET total TO total + nextInput
RECEIVE nextInput FROM (INTEGER) KEYBOARD
END WHILE
SEND total TO DISPLAY
Step 1- Draw a red rectangle around all expressions
Expression evaluator
This example in pseudocode
Uses PLAN Cs original layout
You can adapt to your own purposes
Variables Table
What is printed? (Output)
def input_name():
name = input("What is your name? ")
counter = 1
while counter <= 4:
print("Hello" + name)
counter = counter + 1
Step 1: Draw round all expressionsStep 2: Draw arrows showing the order in which the statements will be executedStep 3: Work through the program filling in the variables table and the Output box
Working out area
Why so much detail in this tracing process?
“We’re confident that, for many, we are moving too fast and creating an impossible cognitive overlad. If
the underlying mechanisms aren’t properly understood, and the facility with the new language isn’t in
place, then
- How can we expect learners to direct their problem solving process towards the tools/mechniams
that are available?
- How can we expect learners to debug programs if they can’t understand what they’ve written, or
determine precisely the effects of each component of the process description they have created.”
(Connors, Cutts and Donaldson, 2015)
Use-Modify-Create
• From Lee et al (2011)
• Describes a pedagogical framework for
teaching computing in the domains of
robotics, game development and …
• This is an ideal framework for structuring
Scratch program development perhaps
• It will be a useful model for physical
computing with the micro:bit for example
• To what extent is it appropriate for text-based
programming?
The PRIMM model – research at KCL
A suggested framework for working with beginners using text-based programming might be:
Predict – given a working program, what do you think it will do? (at a high level of abstraction)
Run – run it and test your prediction
Investigate – get into the nitty gritty. What does each line of code mean? (low level of abstraction). Lots
of activities here: trace, annotate, explain, talk about, identify parts, etc….
Modify – edit the program to make it do different things (high and low levels of abstraction)
Make – design a new program that uses the same nitty gritty but that solves a new problem. This
could be called Create or Design … (not quite sure which is most accurate).
These ideas build on existing research, plus my own experience of teaching programming and the
result of talking to lots of teachers.
(See my latest blog post)
This is a current research project – let me know if you’d like to be a guinea-pig
Not mine Partly mine All mine
Predict - Run – Investigate Modify Make
Use-modify-create adapted
Volunteers needed for next phase of research project to work in this way in school at KS3 and KS4
Materials for PRIMM
Current pilot:
• Pre/Post test
• Teachers using
PRIMM approach
• Interviews
Next study:
• Adapt materials
• Observe lessons
http://blogs.kcl.ac.uk/cser/primm-project/
Other strategies…
Debugging code
• Give students some code with 10 errors
in (a mixture of syntax, logic and
runtime errors). Ask them to circle all
the errors.
Commenting code
• Give students some code and ask them
to write a comment under each line
describing what it does.
Creating a buggy version
- Get students to create a bug-filled
version of code then pass to another
student
- Important thing is that they can explain
why the code doesn’t work with the
errors introduced
Identify parts:
- Spot the variables
- What is the purpose of each variable?
- Find the functions being called 54
What is the value of copying code?
Answer
Summary
Focusing on the pedagogy around teaching programming at school is important
With visual environments the pedagogy may be partially embedded in the tool
With text-based programming students may be disadvantaged by having to write too much code too
soon or copy
Use strategies that focus on understanding of the code and the underlying mechanisms
Expect acquisition of secure conceptual knowledge to take time
Ownership of code is important but knowledge can be very fragile so this needs to be scaffolded
We are involved in various research projects with teachers
to develop Computing pedagogy:
• Jane’s primary survey
• Filiz BBC micro:bit survey
• My PRIMM project
• Trial of Torino with visually impaired primary students
• Threshold concepts in programming
Little plug
New book on CS Education out in March 2018:
Sentance, S, Barendsen, E and Schulte, C. (2018) (Eds).
Computer Science Education: Perspectives on teaching
and learning in schools. Bloomsbury
http://bit.ly/2tSvBey