The I in PRIMM
Code comprehension and questioning
Dr Sue Sentance
29th February 2020
@suesentance
CAS London Conference 2020
Objectives of this session
- To briefly outline the PRIMM methodology and point to
some resources
- To introduce the Block Model as a way of thinking about
programming at different levels
- How we can use questioning and targeted tasks to
support comprehension of program code
- To share some potential tasks around code
comprehension that you could use on Monday!
What can cause learners to struggle with
programming tasks?
Challenges faced Possible reasons …
Perception of
programming as hard –
challenges resilience and
self-efficacy
Programs usually don’t work until many iterations have
passed
There is a “hard” myth (or is it a myth)
Belief in geek gene
Use of “adult” teaching approaches
A working program does
not equate to
understanding of
programming concepts
Too much copying of code without understanding
High cognitive load involved in programming
Focus on product rather than process
Students have
misconceptions &
incorrect mental model
Many misconceptions are known but this has not
transferred into teacher training
Teachers have fragile knowledge & misconceptions too
Programming pedagogy & PRIMM
Some examples:
• Pair programming (Williams & Kessler,
2002)
• Worked examples (Morrison,
Margulieux & Guzdial, 2015)
• Peer instruction (Porter et al, 2011)
• Live coding/ modelling (Rubin, 2013)
• Tracing/ reading code (Lister, many)
• Use-modify-create (Lee et al, 2011)
• Stepwise explanations (Wirth, 2001)
In this context, PRIMM is one approach
to use for programming pedagogy
Specifically it is designed to:
1) Help teachers structure lessons
2) Reflect on the teaching process
3) Cater for varying needs
The PRIMM approach
• Predict – given a working program, talk about it in
pairs or groups. What do you think it will do?
• Run – run it and test your prediction
• Investigate – get into the nitty gritty. What does
each line of code mean? Lots of activities to try
here: trace, annotate, explain, talk about,
identify parts, etc….
• Modify – edit the program to make it do different
things
• Make – design a new program that uses the same
nitty gritty but that solves a new problem
Look at this Python (turtle) code
Discuss with the person next to you
Draw the output
What discussions did you have?
Did you help each other?
What did you learn?
An activity for you – you will need a piece of paper and a companion
Now imagine you could run the program
This is what would actually be output
Did you get it right?
If not, what is different about your answer?
PRIMM Examples
Predict
Run
Investigate
Modify
Make
Lesson 3
PRIMM Examples
Predict
Run
Investigate
Modify
Make
Keep starter programs
on a shared drive
Students should
download, check what
they do and compare
with prediction
PRIMM Examples
Predict
Run
Investigate
Modify
Make
Ask different types of questions
PRIMM Examples
Predict
Run
Investigate
Modify
Make
PRIMM Examples
Predict
Run
Investigate
Modify
Make
PRIMM Examples
Predict
Run
Investigate
Modify
Make
Improve the pizza program so that it doesn’t print out
“and X” at the end. You will have to add an “if”
statement to do this.
Modify the program to have a conversation with
somebody about sport. An example is given below but
you can add your own questions.
Change your triangle function so that it uses a for loop
Write a function pentagon() to create a pentagon (5
sides) with sides length 200
Write a function hexagon() to create a blue hexagon (6
sides) with sides length 50
PRIMM Examples
Predict
Run
Investigate
Modify
Make
Focusing in on Investigate
What are good questions to ask?
Here are two programs (they do the same thing – just choose
the language you prefer!)
What questions might you ask learners to help you gauge their
understanding?
Activity 1: Asking questions
Two versions of the same program
In pairs or threes, think about some good
“Investigate” questions you could ask pupils
to see if they understood the code – and to
prepare them to write something similar
Feedback
Why focus on code comprehension?
• Being able to read and understand code greatly increases
your ability to write code (proven by research)
• Talking about the program means you need the words to
label the various parts – so improves program terminology –
the teacher can help here
• The goal of program comprehension is to allow the
beginner programmer to construct their own mental model.
But how do we know if we are asking the right questions?
And if the pupils can’t answer what does that tell us?
Enter …. The Block Model
What if we could classify tasks and questions?
What is … ?
How would
you …?
Can you spot
the …?
Show me a
… ?
What does …
do?
Granularity of
piece of program
code
Structure ---> Function of program
(M) Macro structure Understanding the
overall structure of the
program text
Understanding the
algorithm underlying a
program
Understanding the
goal/purpose of the
program in the current
context
(R) Relationships Relationships between
blocks
Sequence of function
calls, object sequence
diagrams
Understanding how sub
goals are related to goals
(B) Blocks Regions of interest that
build a unit (syntactically
or semantically)
Operation of a block or
function.
Understanding of the
function of a block of
code.
(A) Atoms Language elements Operation of a
statement.
Function of a statement.
(T) Text Surface (P) Program Execution (F) Function
Architecture/ Structure Relevance /Intention
The Block Model
(M) Macro structure
(R) Relationships
(B) Blocks
(A) Atoms Identify the keywords in
a piece of code
(T) Text Surface (P) Program Execution (F) Function
Architecture/ Structure Relevance /Intention
The Block Model
When a student really understands
the program code they should be
able to answer questions in every
area of the Block Model
(M) Macro structure What does this program
do?
(R) Relationships
(B) Blocks
(A) Atoms Identify the keywords in
a piece of code
(T) Text Surface (P) Program Execution (F) Function
Architecture/ Structure Relevance /Intention
The Block Model
When a student really understands
the program code they should be
able to answer questions in every
area of the Block Model
Activity 2: Types of questions/tasks
In pairs or threes ….
Look at the list of possible tasks/questions around code
comprehension
Where might they fit on the Block Model?
Example
(M) Macro structure Annotate the whole
program showing where
functions are called and
defined.
What set of inputs
could be used to check
all routes/flows through
the program
Summarise what the
program does
(R) Relationships Identify the scope of a
variable
Identify which branch
of an if statement will
never be executed
Identify two blocks of
code which will produce
the same outputs
(B) Blocks Draw a block around an
if statement
Solve a Parson’s
Problem
Give an appropriate
name to a block of code
or function
(A) Atoms List all the integer
variables
Trace a value through
the program code
Identify the purpose of a
single statement
Answer (T) Text Surface (P) Program Execution (F) Function
Architecture/ Structure Relevance /Intention
The Block Model
(M) Macro structure
✓ ✓ ✓
(R) Relationships
✓ ✓ ✓
(B) Blocks
✓ ✓ ✓
(A) Atoms
✓ ✓ ✓
Answer (T) Text Surface (P) Program Execution (F) Function
Architecture/ Structure Relevance /Intention
The Block Model
Carla
Mia
(M) Macro structure
X ✓ ✓
(R) Relationships
✓ ✓ ✓
(B) Blocks
✓ X X
(A) Atoms
✓ X ✓
Answer (T) Text Surface (P) Program Execution (F) Function
Architecture/ Structure Relevance /Intention
The Block Model
Carla
“Novice programmers’ early
comprehension models can be
characterized by a pattern of “holey
knowledge”(i.e. an incomplete
patchwork of fabric, with empty
cells and missing stuffing)” (Schulte
et al, 2010)
Why is it important to ask different types of questions
about the code?
The Holey
Quilt
(gaps in
knowledge)
“Novice programmers’ early
comprehension models can be
characterized by a pattern of “holey
knowledge”(i.e. an incomplete
patchwork of fabric, with empty
cells and missing stuffing)” (Schulte
et al, 2010)
The programming “mental model”
Includes:
- Elements and structure of the program
- Execution behaviour of the program
- Purpose of the whole program
- Purpose of individual blocks
How is the mental model developed? One view ….
Social plane Cognitive plane
(Vygotsky)
Activity 3: Revisiting activity 1
Now look back at the program we looked at earlier
You thought of some questions
Where are these in the Block Model?
Discuss ….
Which tasks and questions are easier to answer than others?
How to progress through different
questions and tasks?
(M) Macro structure Understanding the
overall structure of the
program text
Understanding the
algorithm underlying a
program
Understanding the
goal/purpose of the
program in the current
context
(R) Relationships Relationships between
blocks
Sequence of function
calls, object sequence
diagrams
Understanding how sub
goals are related to goals
(B) Blocks Regions of interest that
build a unit (syntactically
or semantically)
Operation of a block or
function.
Understanding of the
function of a block of
code.
(A) Atoms Language elements Operation of a
statement.
Function of a statement.
(T) Text Surface (P) Program Execution (F) Function
Architecture/ Structure Relevance /Intention
The Block Model
What about progression
through the types of
tasks? ?
What does the program do?
“One interesting observation is that students often have
difficulties explaining the purpose of the whole program (MF),
and if asked to describe the code goal, they explain the
execution of the program (P) and often step-by-step.” (Izu et
al, 2020).
In PRIMM we start with predicting the purpose of a small block
of code. This serves as a reminder that this is not easy for
students, and so simple, short extracts of code should be used.
The goal of predict is to get students used to thinking about
why programs are there and to focus on function first.
Try it out with your classes
Try to ask different questions about programs in your class
Which types of question are most difficult/ easy?
Where is the progression?
Where can we uncover misconceptions?
Try out in your class. Do share any insights with me.
This work is ongoing research. More details will appear at
http://primming.wordpress.com
PRIMM Resources
http://primming.wordpress.com
Materials here that were
used for the two
research studies – and in
time we hope to upload
teachers’ contributions
from their own PRIMM
resources
If you have PRIMM
resources please share
with me!
Summary
- A brief introduction to PRIMM
- The importance of understanding program code
- The Block Model for code comprehension
- Some tasks and questions to use in class
- Remember the holey quilt!
Further reading (if you like depth)
Izu et al (2019). Fostering Program Comprehension in Novice Programmers-Learning Activities and Learning
Trajectories. In Proceedings of the Working Group Reports on Innovation and Technology in Computer Science
Education (pp. 27-52).
Sentance, S., Waite, J., & Kallia, M. (2019). Teaching computer programming with PRIMM: a sociocultural
perspective. Computer Science Education, 29(2-3), 136-176.
Further browsing
http://primming.wordpress.com
Thanks for participating
Contact me at
sue@raspberrypi.org or
sue.sentance@kcl.ac.uk
@suesentance

The I in PRIMM - Code Comprehension and Questioning

  • 1.
    The I inPRIMM Code comprehension and questioning Dr Sue Sentance 29th February 2020 @suesentance CAS London Conference 2020
  • 2.
    Objectives of thissession - To briefly outline the PRIMM methodology and point to some resources - To introduce the Block Model as a way of thinking about programming at different levels - How we can use questioning and targeted tasks to support comprehension of program code - To share some potential tasks around code comprehension that you could use on Monday!
  • 3.
    What can causelearners to struggle with programming tasks? Challenges faced Possible reasons … Perception of programming as hard – challenges resilience and self-efficacy Programs usually don’t work until many iterations have passed There is a “hard” myth (or is it a myth) Belief in geek gene Use of “adult” teaching approaches A working program does not equate to understanding of programming concepts Too much copying of code without understanding High cognitive load involved in programming Focus on product rather than process Students have misconceptions & incorrect mental model Many misconceptions are known but this has not transferred into teacher training Teachers have fragile knowledge & misconceptions too
  • 4.
    Programming pedagogy &PRIMM Some examples: • Pair programming (Williams & Kessler, 2002) • Worked examples (Morrison, Margulieux & Guzdial, 2015) • Peer instruction (Porter et al, 2011) • Live coding/ modelling (Rubin, 2013) • Tracing/ reading code (Lister, many) • Use-modify-create (Lee et al, 2011) • Stepwise explanations (Wirth, 2001) In this context, PRIMM is one approach to use for programming pedagogy Specifically it is designed to: 1) Help teachers structure lessons 2) Reflect on the teaching process 3) Cater for varying needs
  • 5.
    The PRIMM approach •Predict – given a working program, talk about it in pairs or groups. What do you think it will do? • Run – run it and test your prediction • Investigate – get into the nitty gritty. What does each line of code mean? Lots of activities to try here: trace, annotate, explain, talk about, identify parts, etc…. • Modify – edit the program to make it do different things • Make – design a new program that uses the same nitty gritty but that solves a new problem
  • 6.
    Look at thisPython (turtle) code Discuss with the person next to you Draw the output What discussions did you have? Did you help each other? What did you learn? An activity for you – you will need a piece of paper and a companion
  • 7.
    Now imagine youcould run the program This is what would actually be output Did you get it right? If not, what is different about your answer?
  • 8.
  • 9.
    PRIMM Examples Predict Run Investigate Modify Make Keep starterprograms on a shared drive Students should download, check what they do and compare with prediction
  • 10.
  • 11.
  • 12.
  • 13.
    PRIMM Examples Predict Run Investigate Modify Make Improve thepizza program so that it doesn’t print out “and X” at the end. You will have to add an “if” statement to do this. Modify the program to have a conversation with somebody about sport. An example is given below but you can add your own questions. Change your triangle function so that it uses a for loop Write a function pentagon() to create a pentagon (5 sides) with sides length 200 Write a function hexagon() to create a blue hexagon (6 sides) with sides length 50
  • 14.
  • 15.
    Focusing in onInvestigate What are good questions to ask? Here are two programs (they do the same thing – just choose the language you prefer!) What questions might you ask learners to help you gauge their understanding?
  • 16.
    Activity 1: Askingquestions Two versions of the same program In pairs or threes, think about some good “Investigate” questions you could ask pupils to see if they understood the code – and to prepare them to write something similar
  • 17.
  • 18.
    Why focus oncode comprehension? • Being able to read and understand code greatly increases your ability to write code (proven by research) • Talking about the program means you need the words to label the various parts – so improves program terminology – the teacher can help here • The goal of program comprehension is to allow the beginner programmer to construct their own mental model. But how do we know if we are asking the right questions? And if the pupils can’t answer what does that tell us?
  • 19.
    Enter …. TheBlock Model
  • 20.
    What if wecould classify tasks and questions? What is … ? How would you …? Can you spot the …? Show me a … ? What does … do? Granularity of piece of program code Structure ---> Function of program
  • 21.
    (M) Macro structureUnderstanding the overall structure of the program text Understanding the algorithm underlying a program Understanding the goal/purpose of the program in the current context (R) Relationships Relationships between blocks Sequence of function calls, object sequence diagrams Understanding how sub goals are related to goals (B) Blocks Regions of interest that build a unit (syntactically or semantically) Operation of a block or function. Understanding of the function of a block of code. (A) Atoms Language elements Operation of a statement. Function of a statement. (T) Text Surface (P) Program Execution (F) Function Architecture/ Structure Relevance /Intention The Block Model
  • 22.
    (M) Macro structure (R)Relationships (B) Blocks (A) Atoms Identify the keywords in a piece of code (T) Text Surface (P) Program Execution (F) Function Architecture/ Structure Relevance /Intention The Block Model When a student really understands the program code they should be able to answer questions in every area of the Block Model
  • 23.
    (M) Macro structureWhat does this program do? (R) Relationships (B) Blocks (A) Atoms Identify the keywords in a piece of code (T) Text Surface (P) Program Execution (F) Function Architecture/ Structure Relevance /Intention The Block Model When a student really understands the program code they should be able to answer questions in every area of the Block Model
  • 24.
    Activity 2: Typesof questions/tasks In pairs or threes …. Look at the list of possible tasks/questions around code comprehension Where might they fit on the Block Model? Example
  • 25.
    (M) Macro structureAnnotate the whole program showing where functions are called and defined. What set of inputs could be used to check all routes/flows through the program Summarise what the program does (R) Relationships Identify the scope of a variable Identify which branch of an if statement will never be executed Identify two blocks of code which will produce the same outputs (B) Blocks Draw a block around an if statement Solve a Parson’s Problem Give an appropriate name to a block of code or function (A) Atoms List all the integer variables Trace a value through the program code Identify the purpose of a single statement Answer (T) Text Surface (P) Program Execution (F) Function Architecture/ Structure Relevance /Intention The Block Model
  • 26.
    (M) Macro structure ✓✓ ✓ (R) Relationships ✓ ✓ ✓ (B) Blocks ✓ ✓ ✓ (A) Atoms ✓ ✓ ✓ Answer (T) Text Surface (P) Program Execution (F) Function Architecture/ Structure Relevance /Intention The Block Model Carla Mia
  • 27.
    (M) Macro structure X✓ ✓ (R) Relationships ✓ ✓ ✓ (B) Blocks ✓ X X (A) Atoms ✓ X ✓ Answer (T) Text Surface (P) Program Execution (F) Function Architecture/ Structure Relevance /Intention The Block Model Carla “Novice programmers’ early comprehension models can be characterized by a pattern of “holey knowledge”(i.e. an incomplete patchwork of fabric, with empty cells and missing stuffing)” (Schulte et al, 2010)
  • 28.
    Why is itimportant to ask different types of questions about the code? The Holey Quilt (gaps in knowledge) “Novice programmers’ early comprehension models can be characterized by a pattern of “holey knowledge”(i.e. an incomplete patchwork of fabric, with empty cells and missing stuffing)” (Schulte et al, 2010)
  • 29.
    The programming “mentalmodel” Includes: - Elements and structure of the program - Execution behaviour of the program - Purpose of the whole program - Purpose of individual blocks How is the mental model developed? One view …. Social plane Cognitive plane (Vygotsky)
  • 30.
    Activity 3: Revisitingactivity 1 Now look back at the program we looked at earlier You thought of some questions Where are these in the Block Model? Discuss …. Which tasks and questions are easier to answer than others?
  • 31.
    How to progressthrough different questions and tasks?
  • 32.
    (M) Macro structureUnderstanding the overall structure of the program text Understanding the algorithm underlying a program Understanding the goal/purpose of the program in the current context (R) Relationships Relationships between blocks Sequence of function calls, object sequence diagrams Understanding how sub goals are related to goals (B) Blocks Regions of interest that build a unit (syntactically or semantically) Operation of a block or function. Understanding of the function of a block of code. (A) Atoms Language elements Operation of a statement. Function of a statement. (T) Text Surface (P) Program Execution (F) Function Architecture/ Structure Relevance /Intention The Block Model What about progression through the types of tasks? ?
  • 33.
    What does theprogram do? “One interesting observation is that students often have difficulties explaining the purpose of the whole program (MF), and if asked to describe the code goal, they explain the execution of the program (P) and often step-by-step.” (Izu et al, 2020). In PRIMM we start with predicting the purpose of a small block of code. This serves as a reminder that this is not easy for students, and so simple, short extracts of code should be used. The goal of predict is to get students used to thinking about why programs are there and to focus on function first.
  • 34.
    Try it outwith your classes Try to ask different questions about programs in your class Which types of question are most difficult/ easy? Where is the progression? Where can we uncover misconceptions? Try out in your class. Do share any insights with me. This work is ongoing research. More details will appear at http://primming.wordpress.com
  • 35.
    PRIMM Resources http://primming.wordpress.com Materials herethat were used for the two research studies – and in time we hope to upload teachers’ contributions from their own PRIMM resources If you have PRIMM resources please share with me!
  • 36.
    Summary - A briefintroduction to PRIMM - The importance of understanding program code - The Block Model for code comprehension - Some tasks and questions to use in class - Remember the holey quilt! Further reading (if you like depth) Izu et al (2019). Fostering Program Comprehension in Novice Programmers-Learning Activities and Learning Trajectories. In Proceedings of the Working Group Reports on Innovation and Technology in Computer Science Education (pp. 27-52). Sentance, S., Waite, J., & Kallia, M. (2019). Teaching computer programming with PRIMM: a sociocultural perspective. Computer Science Education, 29(2-3), 136-176. Further browsing http://primming.wordpress.com Thanks for participating Contact me at [email protected] or [email protected] @suesentance