Pīkau 11: Communicating well when programming
Why this matters
We don’t really write programs for computers - we write them for people. In this Progress Outcome there are several places that this becomes clear. In the first paragraph of the PO, “Taking account of end users” focuses us on who the program is being written for, and in the last sentence, “they develop programs considering human-computer interaction heuristics” gives some specific ways to get this right.
But computer programs aren’t just written for the user; they are also written for the next programmer who works on the program. It may be that someone will look at your program in a year’s time and need to modify or adjust something in it - it might even be you! That person needs to be able to understand it easily.
So we need to develop skills and habits that help us to communicate well with others, whether it is the user of the program, or someone who needs to work on the program in the future.
Links to existing knowledge
You might already know some of this.
We have been given a taste of how variables work in previous pīkau. Here we go into more depth and explore how they can be used to create efficient programs. If you use spreadsheets you may already be familiar with some of the concepts because they store both text and numbers - different types of data.
Building on what we learnt in Getting programs right: the end-user, and fast algorithms (CT PO 4) about comparator operators (<, >, =) we will now add logical operators to the mix to give our programs more capabilities.
We’ve also seen how block based programming languages relate directly to text based programming languages. This correlation is continued in this pīkau as more advanced programing tools are introduced.
Variables for different types of data
If you are familiar with spreadsheets you may be aware that they have two main types of data they can process: numbers and text. For example, if you type in a phone number such as 035551234, a spreadsheet may see it as a number, and convert it to 35551234. Unfortunately, removing the 0 at the start won’t work if you dial the number. In fact, a telephone “number” isn’t really a number! For example, +64 3 555 1234 contains a plus sign, and sometimes we use dashes, as in 555-1234. These add meaning or make them easier to read, but we don’t intend for the numbers to be treated as values that we can do arithmetic to (such as adding and subtracting). In this case we would want the spreadsheet to treat the telephone numbers as text, even though they are numbers.
On the other hand, an amount like $123 is treated as a number in a spreadsheet, as we might want to add it up in a total. Distinguishing what is really a number, and what is text, can be important in spreadsheets to make sure they are displayed and processed correctly.
The following video explains what is meant in Progress Outcome 5 when it says “variables of different data types”, in the context of programming. The types of variables covered in this video are 'text' (strings), ‘integer’ (int) and ‘floating point number’ (float).
Download the transcript for this video.
A more complete version of the Scratch program demonstrated above can be found on the Scratch website:
A more complete version of the Python program demonstrated above can be found at:
Controlled loops
Quite often we want programs to repeat something until a certain event happens. For example, we want a barrier arm to let cars in until the car park is full; or a self check-out to ask for an item to be scanned until the “Pay now” button is pressed. For this we use a controlled loop. Find out more in the following video.
Download the transcript for this video.
The Scratch programs used in the above demonstration is available from the Scratch website:
Quiz - Can you escape the loop?
This quiz contains screenshots from Scratch.
Scratch is a project of the Scratch Foundation, in collaboration with the Lifelong Kindergarten Group at the MIT Media Lab. It is available for free at https://scratch.mit.edu
Activity - Q1 - Escaping the loop quiz
Instructions: What answer will get the program out of the loop?
Feedback: The correct answer is "any answer over 18".
Activity - Q2 - escaping the loop quiz
Instructions: What answer will get the program out of the ‘repeat until’ loop?
Feedback: The correct answer is "When the number of assignments is the same as the number of students."
Writing for the next programmer
We don’t write programs for computers, we write them for people. Not just the user, but the next programmer! This video explains this more.
Download the transcript for this video.
Many skills of a professional programmer are related to social context rather than the technical one. Blackwell, A. (2002). What is programming? in 14th workshop of the Psychology of Programming Interest Group (pp. 204-218).
As you will have seen in this video, often writing for the next programmer can mean having enough comments to guide the reader through the program. It also means that the names of variables should be chosen thoughtfully to make it clear what their purpose is. Describing what something does in a few words is a challenging task, and we can see that good programming requires good literacy skills.
The Scratch program used in the above video is available at Bad variable names on Scratch.
Using loops in Scratch
There’s more than one way to do it.
For a particular requirement, there can be as many programs as there are programmers. In this video Tim shows different ways of using loops in Scratch to produce different programs with the same result. He then goes on to give an example of how programs can be written effectively to increase their flexibility and robustness (a form of ‘future proofing’).
Download the transcript for this video.
The Scratch programs in the above video are available from EMP10-5 Countdown on Scratch.
Build your own looping program
A “Parsons Problem” is when you’re given all the code needed for a program, but it’s out of order. The following blocks can be used to write a program that counts down to an event (it asks the name of the event, then how long it is until the event; then it has a loop that says how long is remaining, counting down until there are 0 seconds left, at which point it announces the event.
See if you can use the blocks to rebuild the program in Scratch (remember to click on ‘see inside’ to get access to the code).
Using loops in Python
Here Tim takes what he covered in the previous video about using loops in Scratch and translates it into Python.
Download the transcript for this video.
The Python program used in the video is available from TrainedImaginaryAdmins.
Logical and Comparative Operators
(<, >, =, ‘and’, ‘or’ and ‘not’)
The comparator operators (<, >, =) are quite important but on their own we can only compare two things and make a decision. This is where the logical operators (‘and’, ‘or’, and ‘not’) come in. By combining comparator operators with logical operators programs are able to make all sorts of decisions to select what a program will do.
Watch the following video for more about this.
Download the transcript for this video.
The scratch program used in the above video is EMP10 Logical Operators (comparing the user’s age).
In the following video, Tim demonstrates another example of using logical and comparative operators in the context of good days to go fishing according to the day of the lunar month.
Download the transcript for this video.
The scratch program used in the above video is EMP10 Line Fishing.
Quiz - Logical and Comparative Operators
Activity Q1 - Logical and Comparative Operators quiz
Instructions: Which of the following ages will be permitted to enter?
Feedback: The correct answers are 9,10, 50.
Activity Q2 - Logical and Comparative Operators quiz
Instructions: What age does someone have to be to visit my house?
Feedback: The correct answer is 6 to 15 year olds but not 10 years old.
Activity Q3 - Logical and Comparative Operators quiz
Instructions: When is it ‘time for games’?
Feedback: The correct answer is 'When both Marama and Marino are available and it is not raining'.
Activity Q4 - Logical and Comparative Operators quiz
Instructions: What’s the minimum number of answers you will have to give to exit the loop (make the ‘You have enough food.’ message appear)?
Feedback: The correct answer is 10.
Link to programme design
Many skills of a professional programmer are related to social context rather than the technical one
Blackwell, A. (2002). What is programming? in 14th workshop of the Psychology of Programming Interest Group (pp. 204-218).
As pointed out in the quote above, the skills needed for programming can be integrated with the Key Competencies, in particular Relating to others. It is when programmers know their end-users well and use this knowledge that the best programs emerge, and when they communicate well with other programmers that their programs have good “style”.
As in the previous pīkau Getting programs right: the end-user, and fast algorithms, the concepts of comparative ( <, >, =) and logical (‘and’, ‘or’, ‘not’) operators can be used within contexts of other learning areas. For example, in Health and Physical Education, students might describe when foods are healthy, for example when fat < 10g/100g, and sugar < 10g/100g. Or in Science, they might describe the ideal growing conditions for organisms based on warmth being greater than a certain temperature, and moisture being within some range.
The strands of the Technology learning area support teachers and kaiako to incorporate this particular digital content into programmes of learning using technological practice, knowledge and nature of technology achievement objectives.
The progress outcomes up to and including progress outcome 5, describe all the required significant learning steps that students need, typically by the end of year 10, students, “understand the role of systems in managing digital devices, security and application software”.
Progress outcome 5 describes students being able to “independently decompose problems into algorithms. They use these algorithms to create programs with inputs, outputs, sequence, selection using comparative and logical operators and variables of different data types, and iteration”.
A natural connection to the content in this pīkau is the Technological knowledge strand. It contains indicators of progression in Tech Systems that describe what students can do, in NZC Levels 1 to 5 (years 1 to 10), as they build their understanding of how a computer program uses control to transform inputs, into outputs. The progressions described in the strands is broad so that it can relate to any of the 5 areas of Technology:
- computational thinking for digital technologies
- designing and developing digital outcomes
- designing and developing materials outcomes
- designing and developing processed outcomes
- design and visual communication.
Wrapping up and where to next
This pīkau has built further on what we started learning in First steps in programming (CT PO1), Programming with sequence and output (CT PO2), What is programming?, Making the computer do the work: programming with loops (CT PO3) and Getting programs right: the end-user, and fast algorithms (CT PO4). By now we would like to think you have an overview of what programming looks like in the classroom, and are starting to get some insights into computational thinking in general.
To see how what has been covered in this pīkau ties directly back to Progress Outcome 5 watch this video with Tim.
Download the transcript for this video.
As you saw in the video, we have covered most of what is expected of students in the Computational Thinking progress outcome 5 in this pīkau.
HCI (human computer interaction) was introduced in the pīkau Getting programs right: the end-user, and fast algorithms. This will be covered more fully in a separate pīkau, especially the use of “heuristics” for evaluating interfaces.
Binary numbers will also be covered in separate pīkau.
For now you can find more information about binary numbers, including activities to do with your students, from:
Facilitation notes
If you are working through this pīkau as a group feel free to download and use these facilitation notes:
Progress outcome exemplars
Programming in Swift playgrounds:
Pirate Game: