5 minute read
WRITING CODE
n Learning to write code can be a challenge for students, but there are evidence-based approaches to support them Credit: Stock.adobe.com/Gorodenkoff
HOW TO SUPPORT YOUR STUDENTS TO WRITE CODE
Advertisement
Will Grey shares some evidence-based approaches for teaching students to write code
For many children, writing code can be a daunting prospect. To help our students learn to write code, we can use a range of scaffolded pedagogies. Initially, these approaches take ownership of the code away from the students, giving them confidence to explore and experiment. Gradually, as the students gain confidence, we can reduce the amount of support until they are able to write their own programs independently.
On page 70 of this special edition, I shared approaches to support pupils learning to read code. These included activities such as explaining, predicting, and tracing code, as well as live demonstrations with worked examples. Now, I’ll share some evidence-based approaches to support pupils who are learning to write their own code.
Fixing broken code
Children can find and fix common syntax, runtime, and logical errors in a piece of code. These errors might include missing brackets, missing speech marks, spelling mistakes, or missing variable declarations. Pupils can use the programming language’s translator to help find the errors by making the fixes and then running the code to test that it works.
Pupils will need to be made aware of how the errors present themselves – this is unique to each translator and language and is not always obvious. For instance, in the default IDLE Python interpreter, it can be unclear where each error is located. Once pupils are familiar with a variety of common error messages, their causes, and how to fix them, they will be able to debug their own code with greater confidence and resilience. For extra challenge, debugging exercises can be carried out on paper, where there is no feedback from the translator.
Completion problems and pseudocode
We can give children partial solutions to complete. This has scope for a variety of levels of differentiation: as students progress, we can gradually leave out more code. Initially, students might be given most of the code but with parts of some statements missing. Then, we might remove statements completely. Next, we could remove several lines or complete blocks of code. Finally, we could remove all code and only provide comments to the pupils. If these comments are detailed enough, then this is like converting from pseudocode into working code.
At some point, children will need to plan their own code with pseudocode. It is difficult and does require the application of high-level computational thinking, where pupils perform abstraction and code design. A good approach is to get pupils to write the comments for each line of their program before they start coding.
Parson’s Problems
As introduced in my previous article, Parson’s Problems are problems in which the code is presented to children all jumbled up. The aim of the activity is to put the instructions into the correct order so that the whole code performs a specified task. Students do not need to be concerned with remembering syntax and can focus on logic and sequencing. These problems will help develop students’ program comprehension, preparing them for writing their own code.
Modifying code and tinkering
Pupils can make modifications to a piece of code to adapt it for a slightly different purpose. Suppose we have a Scratch program that draws a square. We could ask pupils to modify the code to draw a triangle, pentagon and circle, for instance. We could extend pupils’ understanding and get them to find patterns in the relation between internal angles of a shape and the number of sides – we know finding patterns is a key aspect of computational thinking.
When pupils are modifying and completing code, a crib sheet that provides
n A Python crib sheet that students can refer to when writing code
Planning lessons
We cannot expect children to be able to write code before they have learned how to read code. Through careful planning of lessons and sequences of lessons, we can slowly remove the scaffolding as pupils code and gain increasing ownership of the code as they progress (see page 22).
If we consistently apply scaffolded approaches for reading and writing code in our lessons, we can make the experience of learning to code for children a lot less intimidating, and a good deal more enjoyable.
the basic syntax of constructs with some examples is a helpful aid. Pupils should be encouraged to organise any code that they write so that they can reuse the code in the future. The ability to recognise code that can be adapted to a new context is an important skill.
Pair programming and collaboration
Social constructivist approaches that use collaboration and pair programming, where two students work together on a single computer, can support students who are learning to write code. Within each pair, one student does the coding and the other observes, reviews and gives feedback. Students in each pair should regularly switch roles (see page 58 for more).
A tactical seating plan can be employed – with mixed attainment pairs, or pairs who can challenge each other. Even if each student is working independently on their own code, pupils should still be encouraged to collaborate with their neighbours. Collaborative approaches are often more effective than coding activities where pupils work in isolation without the support of their peers. Moreover, the cooperative and social nature of this approach has been shown to be particularly successful at engaging girls.
gain greater independence as they progress from reading and using code, through modifying code to ultimately writing their own code to solve problems.
The great news is that the PRIMM (Predict, Run, Investigate, Modify, Make) model offers a framework around which we can plan our lessons. For each lesson episode within this structure, we can pick and mix from our assortment of techniques where pupils read code before they write
WILL GREY
Will is head of computing at Comberton Village College, UK, and coordinator of the CAS South Cambridgeshire Community of Practice. He has developed a comprehensive set of resources for A level and GCSE computer science at helloworld.cc/grey.