LOGO Basic bannerLOGO Basic banner

Writing code in any language requires a set of common skills: commands, variables, arrays, loops, and logic. These skills can be taught without a computer. Once these skills have been introduced and learners have practised them, a programming language can be chosen, and the learners can learn that language’s syntax. I assume that many of these skills will be included in the Coding & Robotics Curriculum currently being piloted in South Africa (see the draft CAPS documents here).

It is important to establish whether a student is battling with computational thinking or the syntax of a language when learning to program.

The Process

Writing code, programming, software development — whatever you choose to call it — is a process. In this tutorial, you will see that I have broken this process down into logical sections.

The Specification

Most projects start with some kind of specification: a description of what it is that our program should do. We are going to write a set of instructions — a program — that can draw a simple, regular shape. Because we do not necessarily have the skills to write code in a language such as C, C+, Java, PHP or Python, we will start out writing by writing it in pseudo-code.

Nominate a PCD

Choose a learner who will act as the class’s Programmable Computer Device (“PCD”) and then challenge the class to create a set of instructions that will result in their PCD walking in a simple, regular shape. Let them shout out instructions, while you write down the steps on the board.

1st Iteration: SquareMaker

The first shape is a square. Ask the learners to describe a square to you — after all: how can you write a program to draw a square if you cannot accurately define one? You want them to define it as “a shape with four sides of equal length and four 90 angles”.

This is an example of pseudo-code.

Once they understand exactly what they are drawing, guide the learners towards something like the following set of instructions (written on a whiteboard) for their PCD:

walk forward 10 steps
turn right 90°
walk forward 10 steps
turn right 90°
walk forward 10 steps
turn right 90°
walk forward 10 steps
turn right 90°

Re-writing code to improve it without changing its function is called “refactoring”.

2nd Iteration: the SquareMaker refactored

Ask the learners if they see lots of repetition. Guide them towards seeing that the above 8 instructions are really the repetition of the first 2 steps, 4 times in total. The above “program” can therefore be reduced to something like:

Repeat 4 times:
    walk forward 10 steps
    turn right 90°

It is not that the 1st Iteration is incorrect, but rather that the 2nd Iteration is better, or more elegant.

1st Iteration: TriangleMaker

Using the strategy employed in our SquareMaker program, we are now going to create a program to draw an equilateral triangle (three sides of equal length). The square was probably a bit easier to define, so draw a circle on the board as follows so that they can understand how (and eventually why) we are using 360 degrees/a circle for defining turns:

Try not to give the game away when you explain that now the PCD must turn 120° at each corner — the learners are going to want to tell you that the PCD must turn 60° each time. Let them try that so that they can see that the PCD does not land up on the spot that they started from (which is obviously a requirement for drawing these simple shapes). We want the learners to realise that the total of the turns must equal 360° each time for this to happen.

Repeat the 1st Iteration, this time the objective is to draw a triangle:

walk forward 10 steps
turn right 120°
walk forward 10 steps
turn right 120°
walk forward 10 steps
turn right 120°

2nd Iteration: TriangleMaker

Again: ask the learners what patterns they see. You should end up with:

Repeat 3 times:
    walk forward 10 steps
    turn right 120°

1st Iteration: ShapeMaker

You now have a 2nd iteration of each of your two programs which should look something like this:

Repeat 4 times:
    walk forward 10 steps
    turn right 90°

Repeat 3 times:
    walk forward 10 steps
    turn right 120°

In our next iteration, we are going to abstract the fixed values and replace them with variables.

Abstraction

If they look at the numbers, they should realise that the square (4 sides) has four, 90° turns and a triangle (3 sides) has three 120° turns. If they can see the above pseudo-code and the circle diagram, they should easily now see that they keep coming to a total of 360° for the turns made (they may need some “prompting”!).

Variables

“A variable, in the context of programming, is a symbolic name given to an unknown quantity that permits the name to be used independent of the information it represents. Values of a variable are normally changed during the course of program execution. Variables represent all kinds of data, including booleans, names, integers, arrays, pictures, sounds, scalars, strings, or any object or class of objects depending on the programming language that supports them. The symbolic names of variables are replaced with the actual data location by compilers and interpreters.” [1]

if x = 4
Repeat x times:
    walk forward 10 steps
    turn right 360°/x

if x = 3
Repeat x times:
    walk forward 10 steps
    turn right 360°/x

Looking at the pseudo-code above the learners should quickly see that they can create a new program called ShapeMaker, looking something like this:

Repeat x times:
    walk forward 10 steps
    turn right 360°/x

Now we need to choose a language in which to write our program. Each language has its own syntax so the next step will be to write our program in that language.

LOGO Basic

For this exercise, we will use LOGO Basic, a language that has been around for many, many years and was created exactly for our purpose: learning how to program!

Head on over to Learning to program with LOGO for the next steps!

Scratch

See the tutorial Drawing a square with Scratch.


References:

  1. (2022). Variable. Available at: https://www.techopedia.com/definition/25647/variable-programming (Accessed: 10 November 2023).

By MisterFoxOnline

Mister Fox AKA @MisterFoxOnline is an ICT, IT and CAT Teacher. He has a passion for technology and loves to find solutions to problems using the skills he has learned in the course of his IT career.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from stylus

Subscribe now to keep reading and get access to the full archive.

Continue reading