Live coding
Share this post
Live coding is a great tool and requires a little bravery. It is when you solve a problem in front of your learners and model your thought processes. It is key that your learners see how you code, and not just the final product.
Live coding links really nicely with worked examples and follows similar principles. You might be tempted to use live coding on an ad hoc basis in your lessons, but it is much more beneficial when it is carefully planned to cover the required concepts, consolidate learning, or address common misconceptions.
This 2018 paper states that live coding:
- Makes the process of learning programming easy to understand for novices
- Helps students learn the process of debugging
- Exposes students to good practices
Good practices
You should:
- Talk to your learners and ask them questions
- Narrate your inner monologue
- Make mistakes, either planned or by accident
- Slow down to give your learners time to process
- Show your learners how code moves around; it isn’t just written perfectly from top to bottom
- Be visible; let them see your face; don’t turn your back for too long
- Pause to write things on the board, draw diagrams, and work things out
- Use the largest font possible without losing view of the full line of code
- Break the code down into small chunks (decompose)
Live coding to make a compliments machine
Here is an example live-coding activity that you could try with your learners. This example assumes that they will already know how to find a random integer, but don’t know how to use lists. This coding example allows learners to develop their understanding of computational thinking while introducing a new programming construct.
Scenario
The compliments machine will have a list that stores a variety of compliments. The compliments will then be chosen at random for the user.
Introducing lists
Lists allows us to hold groups of data in one structure. We can create a list to store all of the compliments and then pick one at random.
Here is a list.
compliments = ["You have a wonderful smile", "You are so helpful", "I love how kind you are"]
print(compliments)
You would show the learners that a list looks a little like a variable at first, but then we use square brackets and commas to separate list items. The print function is used to show what is inside the whole list.
Write a few lines, then run it to see what happens. You can use this time to ask questions, or ask the class to make predictions.
Next you tell them that you want to just see one item in the list. Show them the piece of code that would allow them to do this.
random_number=int(input())
print (compliments[random_number])
Run this code and ask your learners what might happen if you type the number 1 into the user input. They might guess that “You have a wonderful smile” will be displayed. This is a common misconception with lists. Try this out to see what happens.
At this point, you can move to your whiteboard and draw the list with the location numbers above, showing them that in Python, lists begin at 0. Running the code again and changing the input to 0 will demonstrate this.
You could then try entering different numbers.
Now that your learners have an understanding of finding a list item, you can show them how to do this randomly.
The # in the code below shows where new code has been added. The line that prints the entire list has been removed, as it is no longer required.
compliments = ["You have a wonderful smile", "You are so helpful", "I love how kind you are"]
random_number = randint(0,2) #
print(compliments[random_number])
What’s this? Another error? What have we forgotten to do? Your class should already have an idea of using functions from other libraries, and will hopefully spot that you haven’t imported randint from random. Add this in and run the code again. Run it a few times to show that it really is random.
from random import randint
compliments = ["You have a wonderful smile", "You are so helpful", "I love how kind you are"]
random_number = randint(0,2)
print(compliments[random_number])
At this point, your learners should have a grasp of:
- How to create a list
- How to call one item in the list
- How to pick an item at random
This is all we need to get us started with a compliments machine. Learners can then adapt and improve the code.
Discuss
- If you have used live coding before, why did you choose this method?
- What tips have you learnt from this step that will help you with live coding in your lessons?
Share this post
Programming Pedagogy in Secondary Schools: Inspiring Computing Teaching

Programming Pedagogy in Secondary Schools: Inspiring Computing Teaching

Reach your personal and professional goals
Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.
Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.
Register to receive updates
-
Create an account to receive our newsletter, course recommendations and promotions.
Register for free