GoalCompare block-based and text-based programming languages and say when each one is a good choice.
New words
block-based language · a language in which a program is built by dragging blocks togethertext-based language · a language in which a program is written by typing codesyntax · the rules for how a text-based language must be writtenprogramming environment · the tool in which programs are written and run
Explanation
Humans give instructions to computers and robots with programs, and there are many programming languages. The two main kinds are block-based and text-based. In a block-based language, such as Scratch, we drag blocks and snap them together. We do not need to remember the commands or type them, and we can use a touchscreen. The blocks limit what we can do, so block languages are mostly used to learn. In a text-based language we type the program and save it as a text file. We must follow the syntax exactly. Text languages are more powerful, and professional programmers use them for big and advanced projects. Python is a popular example. Both kinds use the same ideas: sequence, selection, loops and variables.
Feature
Block-based
Text-based
how we write
drag and drop blocks
type the code
syntax to remember
no
yes
touchscreen
works well
hard to use
power
limited to the blocks
can do much more
mostly used for
learning to program
advanced and professional work
Worked examples
Here is a block program that says Hello! three times. The loop repeats the say block, so we do not need to write it three times.
Python
1for i inrange(3):
2print("Hello!")
Output
Hello!
Hello!
Hello!
This is the same idea in a text-based language. The word for starts the loop. The words print and the quotation marks follow the syntax of the language. The computer prints three lines.
Situation
Better choice
Why
a first project on a school tablet
block-based
no typing, and it works with touch
a team building a large website
text-based
more powerful and more flexible
a quick game to test an idea
block-based
fast to build and change
a program with thousands of lines
text-based
easier to organise and share as files
Different people have different needs, so the best language is the one that suits the job and the person.
Class activity
Language swap (no computer): act as a robot with two ways of receiving instructions. Way 1, blocks: a friend gives you cards with ‘step forward’, ‘turn right’ and ‘repeat 3’ on them and arranges them on the floor. Way 2, typing: the friend must write each command by hand in capital letters on one line, for example FORWARD 2, and you refuse any line with a spelling mistake. Which way was faster? Which way made more mistakes? Which would you give to a 6-year-old? If you have a computer or tablet, look at a block program and a text program side by side with an adult.
Practice
1
Look at the two programs in examples 1 and 2. Name two things that are the same and two things that are different.
The same: both repeat 3 times and both show Hello! three times. Different: the blocks are dragged, but the text is typed; the text needs quotation marks, brackets, a colon and indentation; Scratch shows the words in a speech bubble, but Python prints them as lines.
2
Choose the better type of language for each job and say why. (a) A child who cannot type yet builds a story. (b) A company builds a banking system.
(a) block-based, because it needs no typing and no syntax. (b) text-based, because it is more powerful and suits large, advanced systems.
3
What does syntax mean?
Syntax is the set of rules for how a text-based language must be written, for example where to put brackets, quotation marks and spaces.
4
Which column of the table describes Scratch, and which describes Python?
Feature
A
B
we type the code
yes
no
we drag blocks
no
yes
has strict syntax
yes
no
Column A describes Python (text-based). Column B describes Scratch (block-based).