Syntactic Density - Avoid or Embrace?
There's a current fashion to avoid syntactic density, but is it a fundamental programming idea that we should embrace?
Last week a year 11 student asked one of my colleagues, "What's division?"
It reminded me of Miles Berry's talk at last year's Festival of Computing. He showed a snippet of Python code and asked if anyone could identify what was wrong with it. The first suggestion was that he was using input() to ask a question, rather than printing the question first and then using input() without an argument.
I was fascinated by this, and asked around at the break. Was it usual to print the question on a separate line, e.g. to use:
print("What is your name?")
name = input()
…rather than:
name = input("What is your name?")
My first thought was that it must be related to formatting - in the first case the name entered would appear below the question and in the second case it would appear next to it. But no, the most common reason was that it reduces "syntactic density" and makes the code easier for the students to understand. Someone even told me that asking a question is not one step in the algorithm, but two.
That led me to think about the difference between programming and coding. The key skill in programming is the development of the algorithm, not the coding or syntax. If we think that asking a question isn't a single step, then are we thinking about the implementation rather than the concept - the coding rather than the programming?
If you asked a teenager "Ask your mum whether she wants a cup of tea", would they understand what you meant? I think that most students wouldn't need to be told explicitly to "...and listen for the answer", or "...and let me know what she says." Some people refer to this as context - how explicit you need to be when giving instructions - and it's apparently a cultural thing, e.g. the UK is a higher context culture than the US, for example.
I think that most non-programmers would think that asking a question is a single step - but if you don't, then where do you stop with the decomposition? Are you thinking about the conversion of the string into ASCII for storage in binary inside the computer? Are you also thinking about how the pixels are illuminated on the screen? Before you know it we're writing in assembly language and that's not what GCSE Computer Science is about.
So why did this remind me of the year 11 student who didn't know what division is?
In my GCSE maths classes I find that it's common for students to struggle with division, and even to try to avoid it. I've been pondering why that is, but I'm wondering whether it dates back to the "numeracy hour". People of my age know what division is, but then, in an attempt to make it more "accessible", primary schools introduced "chunking". They were trying to make it easier to learn how to divide, but what they really did was avoid division. Even in year 11, I see students who are asked a question such as "How many 85p pens can you buy for £5?" counting up in 85s until they get to 500.
Scaffolding is a common approach in teaching. Introduce division by teaching "chunking", etc., by all means, but learn when to stop using that method, in the same way that you need to stop using sentence starters in English. Or PRIMM, for that matter. My reservation about PRIMM has always been that people don't stop using it early enough - I wouldn't really use it with a GCSE class for example. As E. M. Forster said, "Spoon-feeding teaches nothing but the shape of the spoon."
One of the issues with assisting students is that helping them can change the nature of the problem. The problem I have with maths is how do you get students to practise using a technique without telling them which technique to use? I teach Pythagoras' theorem, give the students some Pythagoras questions, and they can answer them. But will they understand when it's required? The GCSE paper won't say, "Use Pythagoras' theorem to work out the length of the hypotenuse&hellip"
That's why we need to practice decomposition, which is the key skill in programming - but probably what we're thinking about with the input() example is coding rather than programming.
Coding can mean lots of different things - web-pages are coded with HTML, text can be coded with ASCII or Morse Code, images are coded as bitmaps, data is coded for entry into databases, etc. None of those things is programming, so what's the difference?
If we think of "coding" as how things are presented, then you could say that coding is how we present a step in our algorithm using our programming language of choice, and what's the fundamental skill there?
I would say that "order of evaluation" - how lines of code are evaluated - is the BIDMAS of coding. We teach students about the order in which lines of code are executed, described in GCSE specifications as sequencing, but I rarely hear mention of the order in which individual lines of code are executed. But is it so complex that we should avoid it, as suggested by the input() example?
Children can cope with complexity. You would think it was strange, for example, even at primary level, if I described a house as follows:
- the house is black
- the house is abandoned
- the house is big
- the house is old
Most students, especially at secondary level, wouldn't have any difficulty nesting those ideas for say something the like the big old black abandoned house.
People are also very good at understanding explicit rules from examples. If I said the black abandoned old big house, most people know that it sounded wrong and could come up with more natural sounding alternative even if they didn't even know that there is a rule.
To a certain extent, therefore, students will pick up some of the "order of evaluation" rules through examples such as PRIMM starters or live coding demonstrations - e.g. they will commonly see and understand commands such as print(score+1) or int(input()).
Younger students will also be introduced to complexity by Scratch - the need to use operator tiles limits you to operations on two values at a time, adding further complexity that isn't always the same as BIDMAS.
For example, what would be said in the following examples?




So how should we approach the teaching of programming? Should we find out what's hard and avoid it, or find out what's hard and practice it more? I haven't previously focussed explicitly on "order of evaluation" and unpicking syntactic density, but I'm now planning to do so and will update this blog with any resources that I create.
Postscript
Since uploading this blog I've noticed that there's a question on the 2024 OCR J277 paper 2 that asks for the output of the following code if message = "abcd1234":

This seems to be a GCSE question testing exactly the sort of understanding that I'm describing!
Resources
This blog was originally written in March 2025.