Fertile Questions
for the Languages chapter of “How to Learn Computer Science”.
Welcome
Thank you for buying my book! This page discusses the content in the “Languages” chapter and answers the “Fertile Questions” I asked there. There are no perfect answers, however: you may even disagree, but the point of a fertile question is to make you think.
Here are the questions, and my suggested answers. Do you agree?
1. If we can code in assembly language with instructions like INP, STA and ADD, why do we need high-level languages?
The example given in the book, adding two numbers, requires five instructions in the “LMC” instruction set (see LMC). The Fortran version takes just three, and the Python 4-line version is very easy to understand:
a = int(input())
b = int(input())
sum = a + b
print(sum)
This code uses English words (input, print) and familiar arithmetic. But if INP becoming input was the only difference between high-level languages (HLLs) and low-level languages, we wouldn’t bother switching. It’s more than that. In the book we can see that since ALGOL, high-level languages have provided us with structured programming constructs like IF-THEN-ELSE and WHILE loops. Here is a WHILE loop in LMC assembly language, this one counts down from 10 to 0…
LOOP LDA COUNT
OUT
SUB ONE
STA COUNT
BRP LOOP
HLT
COUNT DAT 10
ONE DAT 1
The same code in Python looks like this:
count = 10
while count >= 0:
print(count)
count = count - 1
Now that we are trying to do something useful with our code, we can see the benefit of using a high-level language: the code is concise, readable and easy to change. In fact, much of the programming constructs we take for granted in HLLs (selection, iteration and subroutines) as well as data structures (arrays and lists etc.) are not available in the low-level language, we must write code to handle those things ourselves, as we did for the countdown example above. For this reason, doing anything complex is far easier in a high-level language.
Finally, HLL code is portable, this means we can code a Python program once and run it on any machine that will run a Python interpreter. The LMC assembly language above will only run on an LMC, likewise low-level Intel code only runs on Intel-family CPUs, and ARM code on ARM processors and so on.
2. Why are there so many programming languages?
to be continued…
- Why do video games have a format, such as PC, Xbox, PlayStation?
- Why did Java become so popular?
- Can a spreadsheet full of formulas be considered a computer program?
- Why do interpreted languages run slower than compiled languages, and why
does this matter less today
Coming soon!
q2
Coming soon!
q3
Coming soon!
q4
Coming soon!