Well met, generous reader. It’s been a while.
As you can probably tell from the total lack of posts, I don’t have much free time. I now work four days a week, and then I work even harder the other three days, looking after my son. My free time is largely spent sleeping to survive, so time where I am both awake and not in charge of a toddler no longer exists. He’s the best thing ever, but having a child has unceremoniously shattered who I thought I was into a million pieces and I haven’t quite finished gluing them back together again yet. For the people who have encountered the jagged edges of this recently, I’m sorry. This is my attempt to claw back something that makes me “me”, and not just “someone’s mum”.
Reader: Oh Codeboom, it’s just you rambling on about life. We were afraid it was a blog post about something important. Yeah, you know like pseudocode – I just hear that word and I shudder.
Reader: Oooooooh, do it again!
Over the last 9 months or so I have been spending an awful lot of time in dangerously close proximity to pseudocode (and earned the dubious title “Queen of pseudocode” – thanks Dave!) I’m talking specifically about pseudocode of the variety used in A level exams (post-16 for anyone not in the UK), although I’m sure everyone has their own special favourite variety. I should be very clear that I’m not aiming to pass judgement on pseudocode in any particular way in this post – I actually think it has both merits and flaws – but here are some of the things I have discovered.
What even is pseudocode?
Here’s a standard classroom conversation I have had so many times:
Teacher: In the exam, you can write in any pseudocode syntax you like, as long as it makes logical sense to the examiner.
Student: What, so we can just write anything?
Teacher: Well no, you have to make sure it’s sufficiently structured as pseudocode.
Student: OK so what’s the syntax we need to follow then?
Teacher: Well you can use any syntax as long as the structure makes logical sense.
Student: Um, what? I’m just going to write in Python.
Students need a computer science Simon Cowell in their head giving a big red X and “it’s a no from me” to avoid writing things that won’t get accepted. However, here’s the scary bit no one tells beginners – YOU ARE SIMON COWELL. To be able to decide when your pseudocode is sufficiently structured to be proper pseudocode and not what I call “rest of the F-ing owl” code (obviously not to students!), you already have to know what you’re doing. But you’re using pseudocode to…learn what to do.
Why are there so many varieties of pseudocode?
I know, I just said that any syntax of pseudocode is acceptable as an answer in an exam. That doesn’t mean that the people who write the exam will write in any old syntax – they obviously have to standardise so that students will know what to expect. In fact, the pseudocode syntax for the AQA and OCR exam boards is completely and utterly different.
This seems to me like a giant waste of resources – if one teacher creates a programming resource with pseudocode and wants to share it with their teacher friend who teaches a different board, someone has to spend hours re-writing the code so that students are able to practice using the format they will see in the exam. AQA pseudocode also has the
← symbol for assignment, which as a non-standard character is somewhat antisocial for people producing home made resources.
How does pseudocode cope with implementation details?
If you’re only familiar with one programming language (perhaps Python), you may not have realised that it’s really hard to make one pseudocode that accurately models the implementation details of every language someone might opt to use for A level. Take this example, where the aim is to extract “NN” from the postcode string.
Here it is in OCR flavour pseudocode, where the arguments are the starting position and the number of characters wanted:
postcode = "LLNNLLL" area = postcode.subString(2, 2) print(area)
Here it is in AQA flavour pseudocode, where the arguments are the starting position, and the ending position (inclusive):
postcode ← "LLNNLLL" area ← SUBSTRING(2, 3, postcode) OUTPUT area
…and here it is in Python, where the slicing operator takes the starting position and the ending position (not inclusive):
postcode = "LLNNLLL" area = postcode[2:4] print(area)
This specific situation actually caused me to write a question for students in pseudocode where my own answer to the question was wrong. I appreciate that it’s really difficult to model every possible implementation decision of every language with an exam specification pseudocode, but it’s this kind of thing that gets some people very hot under the collar about what is ‘right’ and what is teaching bad habits.
So should there be one pseudocode to rule them all?
I don’t know. On the one hand, if there was a standardised pseudocode (and yes, I have heard of HAGGIS) then resources could be written by authors in that pseudocode and easily translated into lots of other ‘real’ programming languages. On the other hand, if there is a standardisation of syntax, is it even ‘pseudo’ any more? This post is already long enough and I haven’t even mentioned the pedagogical side of pseudocode vs other methods, but maybe that’s a post for another day. What do you think?