Programming Concepts · Chapter 1 · Foundations

1.4 Programming Paradigms and Languages

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

Titlepage: double rule over the sans title, one-sentence lede, hairline rule, small-print byline. Paper-white, link-blue accent, zero radius.
Programming Paradigms and Languages · bookSHelf Programming Concepts§1.4

Outline — by the end of this section you will be able to

Learning Objectives

  1. Explain why so many programming languages exist rather than one §1.4.1
  2. Describe the difference between a low-level and a high-level language Def. 1.4.1
  3. Say what a programming paradigm is Def. 1.4.2
  4. Describe procedural and structured programming, and the three structures every program is built from Def. 1.4.3
  5. Describe object-oriented programming and what it bundles together Def. 1.4.4
  6. Explain what it means to call JavaScript a multi-paradigm language §1.4.7
Six objectives, one per click. The tag column names the definition or subsection each objective targets.
Programming Paradigms and Languages · bookSHelf Programming Concepts§1.4

§1.4.1 — why one language will never be enough

Purpose-driven languages

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.

  • JavaScript — interactive web pages; the only language every browser runs
  • Python — data analysis and teaching, prized for being quick to read
  • C — talks closely to the hardware: operating systems, device drivers
  • SQL — asks questions of a database, and nothing else
  • Swift / Kotlin — phone apps, on iOS and Android

Asking which language is best is like asking which tool in a toolbox is best — the honest answer is another question: best for what?

Five languages, each with the job it was built for. The closing line reveals on click as the takeaway.
Programming Paradigms and Languages · bookSHelf Programming Concepts§1.4

Insight Note — the ideas outlast the syntax

The languages come and go faster than the ideas do

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.

Insight Note, named once in the kicker. The elaboration reveals on click.
Programming Paradigms and Languages · bookSHelf Programming Concepts§1.4

Worked example — matching a language to its job

Example: Choosing a Language

Example — Choosing a language

Why can a program written for a web page not simply be written in SQL?

  1. SQL is too slow.
  2. SQL is designed for asking questions of a database, not for building interfaces.
  3. SQL is an older language.

b. Languages are purpose driven. SQL is extremely good at the job it was designed for and cannot do this one at all.

Multiple-choice worked example. The prompt shows first; the solution reveals on click.
Programming Paradigms and Languages · bookSHelf Programming Concepts§1.4

§1.4.2 — how much detail a language makes you handle

Definition: High-Level Language

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.

The definition sits in a ruled paper box beside its animated figure. The clarifying analogy reveals on click.
Programming Paradigms and Languages · bookSHelf Programming Concepts§1.4

Worked example — trading control for speed

Example: Levels

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?

  1. A low-level language, because the program will run faster.
  2. A high-level language, because programmer time is the scarce resource here.
  3. Neither — level of abstraction does not affect development speed.

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.

Second worked example on level of abstraction, this time as a resource trade-off.
Programming Paradigms and Languages · bookSHelf Programming Concepts§1.4

§1.4.3 — a style of organizing code

Definition: Programming Paradigm

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.

Second definition, same ruled-box-plus-figure layout. Names the three paradigms the rest of the deck covers.
Programming Paradigms and Languages · bookSHelf Programming Concepts§1.4

§1.4.4 — a program built from three pieces

Definition: Structured Programming

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.

  • Sequence — do this, then this, then this.
  • Selection — choose between paths depending on a condition (if, switch in Chapter 2).
  • Repetition — do something more than once (loops, in Chapter 2).
Third definition, followed by the three structures it names, revealed one at a time.
Programming Paradigms and Languages · bookSHelf Programming Concepts§1.4

Context Pause — restriction as a feature

Giving up goto made programs possible to reason about

Early 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.

Context Pause, named once in the kicker. The elaboration reveals on click.
Programming Paradigms and Languages · bookSHelf Programming Concepts§1.4

Your turn — name the structure

Try It Now 1.4.1

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.

Try It Now: predict the output, then name which of the three structures the program uses. Result reveals on click.
Programming Paradigms and Languages · bookSHelf Programming Concepts§1.4

Worked example — naming the structures you need

Example: The Three Structures

Example — The three structures

Which of the three structures does “keep asking until the password is correct” need?

  1. Sequence only
  2. Selection and repetition
  3. Neither — this cannot be done with the three structures

b. Repetition to keep asking, and selection to decide whether the password was right. Chapter 2 gives you both.

Worked example applying the three structures just named.
Programming Paradigms and Languages · bookSHelf Programming Concepts§1.4

§1.4.5 — bundling data with behaviour

Definition: Object-Oriented Programming

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.

Fourth definition. The following table develops the procedural-versus-object-oriented contrast.
Programming Paradigms and Languages · bookSHelf Programming Concepts§1.4

§1.4.5 — procedural versus object-oriented, compared

Procedural vs. object-oriented

The contrast with procedural style is the whole point:

ProceduralObject-oriented
Data and behaviourkept separatebundled together
A program isa sequence of steps on dataa set of objects that interact
You mostly writeproceduresobjects 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.

Booktabs table: heavy top/bottom rules, one hairline under the header, no vertical rules. The interpretation reveals on click.
Programming Paradigms and Languages · bookSHelf Programming Concepts§1.4

Insight Note — abstract until you’ve felt the pain

You can’t see the point of bundling data with behaviour until it hurts to not have it

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.

Second Insight Note, on why OOP reads abstractly at this stage. The elaboration reveals on click.
Programming Paradigms and Languages · bookSHelf Programming Concepts§1.4

Worked example — where the behaviour lives

Example: Bundling

Example — Bundling

In object-oriented style, where does the code that changes a bank balance live?

  1. In a separate procedure, away from the balance.
  2. In the account object itself, alongside the balance.
  3. Balances cannot be changed in object-oriented programming.

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.

Final worked example, closing the object-oriented run.
Programming Paradigms and Languages · bookSHelf Programming Concepts§1.4

§1.4.6-1.4.7 — a language that doesn’t have to choose

Functional programming, and JavaScript’s choice not 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.

  • Procedural — Chapters 1-3: variables, conditions, loops, functions
  • Functional — Chapter 3: transforming data without disturbing it
  • Object-oriented — Chapter 5 onward: objects with behaviour

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.

Functional programming plus the chapter map for all three paradigms, closing with the choices-not-rules line.
Programming Paradigms and Languages · bookSHelf Programming Concepts§1.4

Your turn — spot the paradigm

Try It Now 1.4.2

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.

Try It Now: contrast a procedural and an object-oriented snippet that print the same line. Result reveals on click.
Programming Paradigms and Languages · bookSHelf Programming Concepts§1.4

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.

The one headline result the deck allows itself, in a ruled result box, with a dagger footnote quoting the section directly.
Programming Paradigms and Languages · bookSHelf Programming Concepts§1.4

Glossary — terms introduced in this section

Key Terms (1 of 2)

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.

Key terms glossary, first six of eleven, two columns, lifted verbatim. Split across two slides so the 18px projector floor fits without dropping a term.
Programming Paradigms and Languages · bookSHelf Programming Concepts§1.4

Glossary — terms introduced in this section

Key Terms (2 of 2)

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.

Key terms glossary, remaining five of eleven, two columns, lifted verbatim.
1.4
Programming Paradigms and Languages · bookSHelf Programming Concepts§1.4

§1.4 — Conclusions

What to carry forward

The core idea

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.

When the wrong tool fails

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.

Closing argument in two ruled cards — the core idea under a heavy top rule, the failure case beside it — over a ghost section numeral. The next-step line reveals last.