
5 minute read
READ BEFORE YOU WRITE
n It’s important to give students the ability to read and understand code before they start writing it
Will Grey shares some evidence-based approaches for helping pupils to read code
Advertisement
Before students can write code, they need to be able to read code. Computer science pedagogy is often based around the ideas of Piaget’s constructivism (in which pupils develop their knowledge through exploration) and Papert’s constructionism (in which pupils learn through creating artefacts). However, learners need guidance to gain useful knowledge efficiently, and to organise that knowledge in a clear and logical way. They need to be able to break a problem down, remove the unnecessary detail, find patterns, and think algorithmically before they can start to write programs for solving problems.
Just as we wouldn’t expect a young child to write prose before they can read, we need to provide guided approaches that use direct instruction and scaffolding to help our students read code before they can be expected to write code themselves. These guided approaches are needed just as much as, if not more than, creative discovery activities.
Explain the code
My first approach to improving code comprehension is to ask my pupils to explain in plain English what a piece of code does. There are many variations on this activity, but I find that it works well when pupils explain to each other what the code does. That way, pupils have valuable contributions from others that they can then incorporate into their own written explanations.
We could take this further and ask students to carry out various explorations of the code. For instance, pupils could annotate or add comments to code, list and explain the purpose of the variables and functions, and create structure diagrams. I particularly enjoy doing this with the UK’s AQA A level Computer Science prerelease material — a reasonably substantial piece of code that enables a rich investigatory experience (helloworld.cc/aqaprerelease).
Worked examples
Another approach is to use worked examples (see page 90). They can be delivered by modelling with live coding, or by using tutorial guides. In a live-coding demonstration the teacher explains each step of the code as it is being written. This is beneficial because students can see how teachers tackle problems. Pupils also see that
FURTHER READING
Lopez et al. (2008). Relationships between reading, tracing and writing skills in introductory programming. In: Proceedings of the Fourth international Workshop on Computing Education Research. New York. 101-112. helloworld.
cc/lopez2008
making errors is a normal part of the coding process. Another benefit of live coding is that the pace of delivery is generally slow, and this may help some groups of pupils — I have found it particularly helpful with underachieving boys.
Nevertheless, demonstrations need to be kept short and progress only a few steps at a time, so as not to overload working memory. Lessons should have several shorter demonstrations spaced throughout, rather than fewer longer demonstrations. Perhaps live-coding demonstrations could be prerecorded as screencasts with audio and made available to pupils to watch, pause, and replay in their own time, thereby helping pupils who did not follow the first time around. I tend to couple the demonstrations with tutorial guides because it gives my pupils greater autonomy. I have used worked examples across the age ranges to deliver lessons on Scratch to lower secondary pupils, all the way through to advanced concepts in Python such as server-side scripting with sixth-form students.
Sub-goals
The third approach is to group individual steps under meaningful sub-goal labels. In addition to helping students organise and structure the code in a coherent manner, this reduces the load on working memory because individual steps are chunked together. Pupils could be asked to do this themselves, or sub-goal labels could be provided by the teacher, according to the specific needs of the student.
Trace the code
Tracing code by hand to simulate the outcome of each instruction in an algorithm is another method (see previous article).
Putting it all together
This is where the student replicates the task of the computer by keeping track and recording the values of the variables at each step, and performing the various arithmetic and logical operations. Pupils find tracing code tricky, as it requires considerable patience and concentration to not lose their train of thought. It takes practice to master, especially when tracing recursive algorithms like merge sort. I tend to practise these regularly with my GCSE and A level groups – both with the familiar algorithms for searching, sorting, and traversing, and with algorithms they have not seen before. There are plenty of past paper questions across the exam boards that can be used support this activity (see the previous article for more).
Once pupils have gained comprehension of the various programming constructs and seen them applied in different contexts, they will be able to write better code. There are many scaffolded techniques that can help students write code by n An example of a Parson’s Problem: can you rearrange the code to draw a square? taking away the challenges of code design and abstraction. These ideas for reading code are generally very simple to implement, and can be used together and alongside methods for writing code and more general teaching pedagogies, such as flipped learning, direct instruction, questioning, and verbal feedback, to deliver effective lessons on coding in visual and textual languages to schoolchildren of all ages.

Parson’s Problems
Parson’s Problems bridge the gap between reading and writing code (see page 80). Here, code is presented to pupils jumbled up. The task is to put the instructions into the correct order so that the whole code performs a predefined task. Students do not need to be concerned with remembering syntax, and can focus on logic and sequencing. They make a lovely starter activity, and can come in a variety of forms, from those on a computer to paper-based and jigsaw-type puzzles with snippets of code that can be pieced together —but these do require quite a bit of preparation.

WILL GREY
Will is head of computing at Comberton Village College in the 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.