How do you actually teach programming?

This is a question which has been bugging me for some time now – how do you actually teach someone to program? I don’t mean which language, or what resources should I use, or what time of the day is optimal. I mean what is it in your teaching which switches on the little lightbulb that makes a student able to think through the logic of what they want to do and translate that into code? I have recently been working on my Spanish using Duolingo and I sense that my own language learning is a little like what I’m seeing in the classroom with students who learn to code.

Here are the stages I often see in the classroom:

Syntax wizard
This is the first stage where the student is confident to use familiar concepts such as input, print, if/else etc. The student can memorize syntax and fix any errors that may occur. Confidence at this stage is usually quite high as it is early on in the learning journey, and you have probably provided a lot of help as well as offering fairly small and basic tasks. (Check out the super awesome diagram below produced by my art department.)



Pile of Lego
This bit is horrible for teachers. So, you’ve given your students a huge pile of programming building blocks to work with – they have understood conditions, loops, arrays, all the basics are there. So there you are with your special occasion turquoise pen, filling in your planner with glee, when you decide to set a more difficult task which combines some of these together. Here’s my favourite example of such a piece of thinking:

Teacher: Hmm, okay. I’ve taught input, loops and the % operator and everyone in the class did really well in those lessons. I know! Let’s put these familiar things together and ask them to write a program where they enter a number and the program prints out all of the even integers from 1 to the number they entered. 

Student: Burrr…what’s an integer?

Now, of course your students have not completely forgotten everything they once knew. They have just worked themselves into a panic (warning, this panic is contagious) because you asked them to put together more than one thing at once. It’s a bit like when on my Spanish Duolingo practice it asks me to write something involving two different tenses and some bit of vocab I only just learnt. Give me a test on each of these things individually and it’s ¡muy bien hecho!, but make me do them all together and it’s not exactly creme de la menthe, if you catch my drift Rodney.

Typewriter monkey
Upset by the loss of their former syntax wielding wizard glory where the challenges were easy and the gratification was quick (thanks a LOT, smartphone game culture x_x), students often get disheartened. Now, the way to program really difficult stuff goes something like this:

  1. Write some code. It doesn’t matter what it does, or even if you have any idea what it is supposed to do.
  2. Run your program
  3. If it doesn’t work, delete words and/or syntax from the code COMPLETELY AT RANDOM.
  4. Repeat 1-3 until either the code works, someone tells you the answer, or it’s the end of the lesson.


This is where the journey ends for some of the brave adventurers, they choose the wrong path*, Treguard packs them off home with a knapsack and they never enter the computer room again. However, for those who prevail, one day they turn up as…

Code Kitten
This student can code. They understand how to put together the building blocks and they aren’t phased by bigger programming tasks, e.g. programming hangman, noughts and crosses etc. They can think through how they will represent what they need to do using variables and data structures, and whilst they are only a kitten in experience terms, they are more than scrappy enough to hold their own in most tasks. I’d say this equates to a working fluency in a different language – good enough for most everyday situations, not good enough to read a newspaper.

But the question I ask is…how do you get your students from monkey to kitten? What is it in your lesson that takes them from random button bashing to confidence in building up their own code? For me, it’s all about the way I teach them to plan. Teaching syntax is satisfying and straightforward, indeed many ‘learn to code’ resources don’t go past the syntax wizard stage because they don’t want the student to lose interest. Teaching mastery is hard. But… that’s a post for another time 🙂


* By the wrong path I mean they probably opted to do something else instead of Computer Science GCSE. 😉

13 thoughts on “How do you actually teach programming?

  1. ive been working on this exact thing. im still at the “throw things at the wall to see what sticks” stage. but ive had some luck so far, so pardon the overlap with your strategy so i can be complete:

    1. i do a 45 minute intro aimed at non-coders, with a live coding demo at the end. i cover 6 of 7 basic concepts in it: variables, input, output, loops, basic math, and conditionals. (7 is functions.)

    2. i read a story called “the robot hypnotist,” which reinforces all 7 concepts without actual code.

    3. i have a cheat sheet with all 90-something commands (legos) and ask the person to pick out the ones that look interesting. i explain those.

    4. similar to the 45-minute introduction of concepts, ive walked students through coding some easy interactive scripts, focusing on line input and if-then (in a loop.)

    5. ive actually covered 60 of the commands in one sitting. granted, this took at least a couple hours. (making this fun was a challenge i would have never thought i was up to. this was one-on-one tutoring, by the way.)

    6. the first time i taught for loops, someone managed to get the impression that theyre the basic structure for every program. ive been working on diverse examples to avoid this impression.

    7. what im building up to is more collaboration like in step 4. i never miss an opportunity to explain concepts in the simplest way possible, and how they can help the user/coder.

    when i was learning, i liked to take existing programs, cut out the parts i didnt understand (i struggled with gosub when i was very young, so i “fixed” programs that used it) and made changes to make it work the way i wanted.

    im very impressed with the variety of tools that are out there, but i intend to teach in exactly that way that worked for me. since i know that wont work for everyone, i just plan to keep trying things and quickly drop what doesnt assist the learner and myself at the same time.

    this requires lots of time, but the person im teaching right now i dont get to see every month. im currently looking to build up in a way that hopefully sticks for long periods by illustrating the workings, and having conversations about solving problems. we do code and i would like to do more, but im very happy when the concepts stick.

    i taught myself hands-on, and i believe in hands-on. but i learned through constant experimentation, and i think currently there is slightly too much hands on with too little guidance and explanation. ymmv, but see how simple you can make explaining the concepts of coding: how to build things up, and how to get them into smaller steps.

    also have a look at the scratch/python book coding for kids (something like that) from dk. i dont use it directly, but its likely to provide inspiration if you thumb through it. ive been focused on adults, but if you dont talk down to them you can have just as much fun and computer-play as you likely would teaching kids.

    i design with everyone in mind, including my 7-year-old self teaching/learning basic; i dont target any age group, i try to talk to anyone that can do a search on google.

  2. How did *you* learn to code? If you were anything like me, you learnt by copying other people’s programs (I must have typed in 1000s of lines of Sinclair BASIC into my ZX Spectrum, copied from magazines!), modifying them, and then seeing what happened. After a while you started adding bits, writing similar ones, etc. You slowly became a programmer out of curiosity – not because someone showed you how to code.

    I’ve taken so many kids through the same set of lessons…
    1. This is the concept of sequence! Got it? Yes!
    2. This is the concept of a loop! Got it? Yes!
    3. This is the concept of branching! Got it? Yes!
    4. Ok, now you know the building blocks of programming, PUT THEM ALL TOGETHER!

    It just doesn’t work for most students… It’s not knowing all of the ‘lego blocks’ that students need, it’s the ability to break a problem down mentally, and formulate a solution. This is why it’s so hard to teach… we’re actually trying to teach *problem-solving*.

    So now I tend to give students pre-made programs to investigate, to play with, to have fun with (whether it’s in Scratch, Python, or Java)… They really enjoy hacking these about, and before you know it, they’re customising them… They’re programming! Later on, I can formalise the teaching of concepts.

  3. With my Y9 (age 13/14) I’ve been doing a ‘Scratch to Java’ unit. This consists of three main stages for each programming technique:

    1. A worked Scratch example.
    2. The same program as a worked Java example
    3. A differentiated independent task based on the skill (from ‘very similar but a bit different’ to ‘you need to find out how to add these extra features that you haven’t been taught’).

    Finally, a put it all together task, differentiated once again so the lego, monkey and kitten kids can (hopefully) all access it.

    I’ve made a website for the whole unit if you’re interested in seeing it in action:

    1. A possibility worth considering for blocks based to text based programming have a look at Snap! ( and load the Codification example project. This lets you write a block in Snap! (basically Scratch) and then see the text equivalent in Python, Javascript, C, Smalltalk (I think Java wouldn’t be too difficult to add since all you do is define what the text equivalent of each Snap! block is)

  4. When we hit the Lego stage I try to concentrate on design.
    The simple version is – if its not in your design (flowchart, psuedocode, scribbled notes), you don’t get help.
    Once they start realising that working out what you want it to do is the important part, we start to get somewhere.

  5. Exactly my experience of what happens! Apart from me calling them Code Kittens. But then again a more than competent programmer I taught coded Nyan Cat with my face on it in VB so your model is scarily accurate.

  6. This is a problem I’ve struggled with for a long time. I don’t have anything concrete yet, but I feel like I’m making progress. Some thoughts:

    * students that I have ‘taught’ have gone on to work as programmers
    * more of my students as a percentage of the class are able to put working programs together than in previous years

    What limited success I’ve had in this arena so far has come from allowing students the space the develop rather than direction or instruction.

    The comparison to language is interesting. I was ‘taught’ letter recognition, writing, and pronunciation. I was ‘taught’ spelling and word meanings. I was ‘taught’ syntax, grammar, and writing idioms. I’m not sure I was ever ‘taught’ how to write. I learned that by reading a lot. And what got me reading a lot, more than anything else, were choose your own adventure books. They might not have been particularly well written, but they did focus on comprehension. You had to interpret the meaning of the writing to make progress in the games.

    Reading this, and writing that, has inspired me to try a new exercise with my students when I next get the chance. The rough idea will be to provide some code that solves a particular problem and have them trace the program in the debugger, guessing where the program counter will go next or what the values of the variables will hold a various points. Maybe I’ll introduce a subtle bug that they’ll only find by stepping through line by line.

    1. That’s a good idea for an exercise! 🙂 Let me know how it goes. I did manual tracing today with a recursive and iterative algorithm for A-Level. It did result in an “a-ha” moment!

    2. I also keep trying to figure out how to be a better code teacher. I think you really have something when you say you give your students space to develop. I’ve been doing much the same thing – though I never analysed it before.

      I do teach basic syntax in the beginning. I also use worked examples in class, code samples they copy, look at and change and also setting problems for them to solve which involve them using the syntax they have learned. I also encourage them to do their own exploration. I also teach them how to plan.

      Lately I am seeing my students become excellent coders, unafraid of challenges, before my very eyes. I am not sure it is something I have specifically done, but rather the whole atmosphere that suddenly pops together.

      I have also found it helps to tell them specifically tell hem that they need to be willing to fail before they get it all right. I usually ask one of my good coders to tell the others how many times a program they have written works perfectly first time – almost never. Coding is a great space to learn how to fail successfully – to fail as a part of learning, but not to get wiped out by that failure. Rather it becomes part of the journey to success as the student learns how to find and fix their own errors.

      Whatever it is that makes for this success rate in coders I am seeing now is great. I do teach high school students which can also make a difference.

  7. yep, edulysis has it right as far as I am concerned.

    My Problem Solving Paradigm: (invented today for my Year 10s, after much work on this):

    1. Write down exactly what you want to happen. E.g. If your class are driving you mad, go to door, open door, go out of classroom, find wall, repeat banging head against wall until pain stops. (They liked that).

    2. Find the logical structure in the problem using what you wrote down in 1 above using the 3 structure elements: sequence, selection and iteration and draw the logical structure chart (flowchart okayish, structure (JSP) much better).

    3. Look at your structure chart, use it to write the code (simplest stage – look up syntax if you need to).

    The ONLY hard thing about coding is missing out steps 1 and 2. If you do not know exactly what you need to do before you start and do not know the structure then you will not be able to code. If you do know 1 and 2 then coding is trivial. Fortunately 1 and 2 and then 3 is much, much easier than attempting to do 1+2+3 in one shot.

    So: write, draw, code.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: