Section 1.4 · Foundations
Why are there so many languages?
Thousands of them, and more every year.
- They differ in the job they were built for
- They differ in their distance from the hardware
- They differ in what they expect a program to be made of
1 · purpose
JavaScript
interactive web pages — the one language every browser runs
Python
data analysis and teaching — prized for being quick to read
C
where a program must talk closely to the hardware
SQL
asking questions of a database, and nothing else
Swift · Kotlin
phone apps, on iOS and Android respectively
2 · level of abstraction — how far from the machine
high-level
Say what you want. Faster to write,
and whole categories of mistake
become impossible.
> let total = 5 + 3;
> console.log(total);
8
low-level
Say how the hardware does it — where each value sits in memory,
and exactly how each calculation happens. Extremely fast to run, far slower to
write, far easier to get wrong.
3 · paradigm
procedural
a sequence of steps on data
- Data and behaviour kept apart
- You mostly write procedures
- Direct, and easy to follow for a small job
object-oriented
a set of objects that interact
- Data and behaviour bundled together
- You mostly write objects and methods
- Pays off as a program grows
functional
same input, same result, nothing else touched
- Produces new values rather than changing old ones
- Easier to test and to reason about
balance
deposit()
procedural — kept apart
account { balance, deposit() }
object-oriented — bundled
structured programming
sequence · selection · repetition
every program can be built from these three, and nothing more exotic
goto
Jump anywhere, and reading one line tells you nothing
about how you arrived there.
JavaScript is multi-paradigm — all three, one language