Programming Concepts · Chapter 1 · Foundations
Why thousands of languages exist, what separates low-level from high-level, and the three paradigms — procedural, object-oriented, functional — that shape how a program gets organized.
bookSHelf · Introduction to Programming Concepts · §1.4 · a self-paced section
Outline — by the end of this section you will be able to
§1.4.1 — why one language will never be enough
There are thousands of programming languages, and new ones appear every year. A reasonable first reaction is that one good language should do — but languages are purpose driven: the choices that make a language good at one job make it worse at another.
Asking which language is best is like asking which tool in a toolbox is best — the honest answer is another question: best for what?
Insight Note — the ideas outlast the syntax
Variables, conditions, loops, functions and data structures appear in nearly all of them — which is why this course is called Programming Concepts rather than JavaScript. Learning your second language is dramatically faster than your first, because the second time you are only learning new spellings for things you already understand.
Worked example — matching a language to its job
Example — Choosing a language
Why can a program written for a web page not simply be written in SQL?
b. Languages are purpose driven. SQL is extremely good at the job it was designed for and cannot do this one at all.
§1.4.2 — how much detail a language makes you handle
Definition 1.4.1 — High-Level Language
A high-level language is one with a high level of abstraction: it hides hardware details such as memory addresses, so the programmer describes what should happen rather than exactly how the hardware should do it. JavaScript is a high-level language.
Definition 1.4.1: High-Level Language.
A comparison that holds up well: cooking a meal entirely from scratch gives you control over every ingredient and takes all afternoon. Cooking with prepared ingredients is far quicker, and you accept someone else’s choices about what’s in them. Neither is the right answer in general — it depends on whether the afternoon or the control matters more.
Worked example — trading control for speed
Example — Levels
Mai Vang leads a small team that has three weeks to ship a working web app. Which is the better trade-off for her?
b. Both trade-offs are real, so the answer depends on what’s scarce. Mai has three weeks and a small team, so developer time matters more to her than the last few percent of speed — a high-level language wins. That describes most web work.
§1.4.3 — a style of organizing code
Definition 1.4.2 — Programming Paradigm
A programming paradigm is an approach to organizing and structuring code. It shapes how a program is broken into pieces and how those pieces fit together.
Definition 1.4.2: Programming Paradigm.
The three worth knowing at this stage are procedural, object-oriented, and functional. You will write all three later in the book — the goal here is to recognize them.
§1.4.4 — a program built from three pieces
Definition 1.4.3 — Structured Programming
Structured programming is a discipline in which programs are built only from sequence, selection, and repetition, with no arbitrary jumps between parts of the program. Any computation can be expressed with these three structures.
Definition 1.4.3: Structured Programming.
if, switch in Chapter 2).Context Pause — restriction as a feature
goto made programs possible to reason aboutEarly languages let a program jump to any line at any time, with an instruction usually called goto. It worked, and it produced programs nobody could follow, because reading one line told you nothing about how you had arrived there. This is the first example in the course of a restriction being a feature.
Your turn — name the structure
Try It Now 1.4.1
Run this code and predict the total before you check the output.
let subtotal = 25; let tax = subtotal * 0.08; let total = subtotal + tax; console.log(total);
What you should see: 27
Which of the three structures does this program use — sequence, selection, repetition, or some combination?
Sequence only. Three assignments and a print, each running once, top to bottom, with no branching and nothing repeated. There is no if (no selection) and nothing runs more than once (no repetition) — Chapter 2 introduces both.
Worked example — naming the structures you need
Example — The three structures
Which of the three structures does “keep asking until the password is correct” need?
b. Repetition to keep asking, and selection to decide whether the password was right. Chapter 2 gives you both.
§1.4.5 — bundling data with behaviour
Definition 1.4.4 — Object-Oriented Programming
Object-oriented programming is a paradigm that organizes a program around objects, each bundling data (its properties) with the behaviour that operates on that data (its methods).
Definition 1.4.4: Object-Oriented Programming.
§1.4.5 — procedural versus object-oriented, compared
The contrast with procedural style is the whole point:
| Procedural | Object-oriented | |
|---|---|---|
| Data and behaviour | kept separate | bundled together |
| A program is | a sequence of steps on data | a set of objects that interact |
| You mostly write | procedures | objects and their methods |
Table 1.4.1: procedural versus object-oriented programming compared.
Read it: procedural code is direct and easy to follow for a small job. Object-oriented code pays off as a program grows, because each object keeps its own data in order and you can use one without knowing how it works inside.
Insight Note — abstract until you’ve felt the pain
OOP is the fourth of this course’s learning outcomes and the target of Chapter 5, so it’s fine — expected, even — to find this description abstract right now. Chapter 5 builds a program big enough to make the point.
Worked example — where the behaviour lives
Example — Bundling
In object-oriented style, where does the code that changes a bank balance live?
b. In the account object itself, alongside the balance. That bundling of data with the behaviour that acts on it is exactly what makes the style object-oriented.
§1.4.6-1.4.7 — a language that doesn’t have to choose
Functional programming organizes a program around functions in the mathematical sense: give one the same input and it always returns the same output, changing nothing else along the way. Its distinctive habit is avoiding change — a functional program produces a new value rather than modifying the old one.
These are choices, not rules. A game might hold each character as an object, use a loop to update them, and transform a list of scores functionally — all in the same file, all in one language.
Your turn — spot the paradigm
Try It Now 1.4.2
Both snippets below print the same line, and both are valid JavaScript. Run them and compare.
Snippet A
let title = "JavaScript Guide"; let pages = 200; console.log(title + " has " + pages + " pages.");
Snippet B
let book = { title: "JavaScript Guide",
pages: 200 };
console.log(book.title + " has " +
book.pages + " pages.");
What you should see (both snippets): JavaScript Guide has 200 pages.
Which snippet is procedural and which is object-oriented? What tells you?
Snippet A is procedural: the data (title, pages) sits in two separate variables, and console.log — the procedure — reaches in from outside to use them. Snippet B is object-oriented: the same data is bundled into one book value. It does not yet carry a method of its own (methods arrive in Chapter 5), but the data is already organized the object-oriented way. What marks the style is not whether an object appears, but where the data lives relative to the code that uses it — spread across separate variables, or bundled into one value.
The headline result
JavaScript is multi-paradigm
It supports all three organizing styles — procedural, object-oriented, and functional — rather than committing to just one.
That is unusual, and it is a real advantage for a first language: you can meet each idea without changing languages to do it.
† A game might hold each character as an object, use a loop to update them, and transform a list of scores functionally — all in the same file, all in one language.
Glossary — terms introduced in this section
Purpose driven
The principle that a language is designed for a kind of work, which is why so many exist and why “which is best” is not a well-formed question.
Level of abstraction
How far a language sits from the hardware; how much machine detail it hides.
Low-level language
One where the programmer describes the work in terms the hardware handles directly. Fast to run, slow to write.
High-level language
One that hides hardware details so the programmer says what should happen rather than how. JavaScript is one.
Programming paradigm
A style of organizing a program; a set of ideas about what a program is made of.
Procedural programming
Organizing a program as a sequence of instructions acting on separately held data.
Glossary — terms introduced in this section
Structured programming
Building programs only from sequence, selection and repetition, with no arbitrary jumps. Any computation can be expressed this way.
Sequence, selection, repetition
The three structures: in order, choose a path, do it again.
Object-oriented programming
Organizing a program around objects that bundle data with the behaviour acting on it.
Functional programming
Organizing a program around functions that always give the same output for the same input and change nothing else.
Multi-paradigm
A language supporting more than one of these styles. JavaScript supports all three.
§1.4 — Conclusions
A language is chosen because it’s purpose driven — good at one kind of work and worse at another. Once chosen, a paradigm — procedural, object-oriented, or functional — shapes how you organize the code inside it. JavaScript supports all three.
SQL can ask a database questions and nothing else — write a web page’s interface in it and the language has no concept of a screen or a click. Purpose-driven design cuts both ways: sharpest at its job, unusable outside it.
Next: §1.5 Program Design Tools and Environments. Back to start.