Introduction to Programming Concepts and Methodologies · Chapter 1 · Foundations

Program Design Tools and Environments

Before any code gets written, computational thinking breaks the problem apart — then pseudocode and flowcharts let you plan the solution in a form no compiler ever checks.


bookSHelf · Introduction to Programming Concepts and Methodologies · §1.5 · a self-paced section

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

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

Objectives

  1. Define computational thinking and name the four techniques it is built from Def. 1.5.1
  2. Break a problem down, spot its patterns, and strip it back to what matters §1.5.2–1.5.3
  3. Write pseudocode for a task and read a flowchart's three basic shapes Def. 1.5.5–1.5.6
  4. Run JavaScript in the browser console and in a code editor §1.5.7
  5. Read an error message and use console.log to find out what a program is really doing §1.5.8–1.5.9
1.5

§1.5.1 — the two problems typing solves only one of

A program has two separate difficulties: working out what the steps are, and writing those steps in JavaScript. Doing both at once means you can never tell which one you're stuck on.

Think before you type.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

Context Pause — the bridge, not the machine

A computer does exactly what you tell it, at enormous speed — including the wrong thing.

Everything that decides whether the answer is right happens before the first line of code. That is the part this section is about.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.1 — the name for the thinking half

Definition 1.5.1: Computational Thinking

Definition 1.5.1 — Computational Thinking

Computational thinking is a problem-solving process, rooted in principles from computer science, that breaks a complex problem into smaller, more manageable parts and devises systematic approaches to solve them. A complex problem is one that is difficult because it involves many different interrelated parts or factors.

Figure 1.5.1 — Computational thinking ring Eight component skills of computational thinking arranged clockwise from the top in a ring of circles - Decomposition, Pattern recognition, Abstraction, Algorithm, Generalization, Evaluation, Modeling, Simulation - joined by gentle outward-curving connector arcs, surrounding a central ellipse labelled Computational thinking. Alternating circles are outlined in the CURVE and ACCENT tones purely to separate neighbours; the alternation carries no meaning of its own. Decom-position Patternrecognition Abstraction Algorithm General-ization Evaluation Modeling Simulation Computationalthinking

Figure 1.5.1: This diagram illustrates the main components of computational thinking.

Computational thinking is the bridge between the problem and its resolution — it lets you separate a problem's parts and form solutions both computers and people can follow.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

Insight — a plan has no language

The same plan can be written several different ways.

Section 2.2 makes this concrete: an algorithm is a plan that exists before any code does. The tools here are how you write a plan down before it has a language.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.1 — a shorter framing

The three As

ISTE lists computational thinking's components in full, but a shorter framing compresses them into three moves: abstraction, automation, analysis.

Figure 1.5.2 — The three As: abstraction, automation, analysis Abstraction (top, "Formation of problem"), Automation (bottom right, "Expression of solution") and Analysis (bottom left, "Execution and evaluation of solution") arranged around a ring of three curved arrows that hand off clockwise, Abstraction to Automation to Analysis and back to Abstraction. The ring surrounds a hub reading "Human abilities/ computer affordances". Each station carries an unframed schematic icon: a cluster of scattered points and short strokes flowing through an arrow into a single dot inside a small square (Abstraction); three equal ordered bars flowing through an arrow into a gear (Automation); a small lined result box beside a check mark and a cross mark (Analysis). Static figure, no motion. Human abilities/ computer affordances Abstraction Formation of problem Automation Expression of solution Analysis Execution and evaluation of solution

Figure 1.5.2: The three As — abstraction, automation, analysis — illustrate the power of computational thinking.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.1 — taught as four techniques

The four cornerstones

In practice, computational thinking is usually taught as four techniques — a systematic way to attack a problem using tools such as data structures.

Figure 1.5.3 -- the four cornerstones of computational thinking A head-in-profile outline containing a solid brain shape sits at the centre. Four straight spokes reach out to four labelled corner panels -- Algorithms at top-left, Decomposition at top-right, Abstraction at bottom-left, Logical thinking at bottom-right. Each panel is a coloured title bar over a lighter body holding a small schematic icon: a mini flowchart (start circle, decision diamond, process pill) for Algorithms; two overlapping squares standing in for interlocking pieces for Decomposition; an outline cone narrowing to a solid triangle for Abstraction; a lightbulb with five rays for Logical thinking. Algorithms Decomposition Abstraction Logical thinking

Figure 1.5.3: Users can explore the essence of computational thinking through decomposition, logical thinking, abstraction, and algorithms.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.1 — Practice

Try It Now 1.5.1

Try It Now 1.5.1

Before reading on, list five instructions you would give a robot to make a jam sandwich. Then hand the list to a classmate — he is playing the robot, and he follows every instruction completely literally. Which one breaks first?

Answers vary, but nearly every list breaks in the same places: "Get the bread" — from where? "Spread the jam" — with what, the knife was never picked up. "Put the bread on the plate" — which bread, which side up? Ordinary instructions rely on an enormous amount of unstated knowledge, and a computer has none of it.

1.5

§1.5.2 — the first two techniques, applied

Decomposition breaks a hard task into components; pattern recognition groups what decomposition turns up into categories you can act on.

Break it down. Then look for the pattern.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.2 — breaking a problem into self-contained parts

Definition 1.5.2: Decomposition

Definition 1.5.2 — Decomposition

Decomposition is the analytical process of breaking a complex problem or system into smaller, self-contained parts that can be understood and solved on their own.

Definition 1.5.2 — Decomposition One whole-problem box breaks into ten labelled parts, three at a time by column, then the empty box fades out and only the parts remain. The Jam Sandwich Problem Ingredients Bread Jam Butter Equipment Plate Knife Actions Repeat x times Left hand (LH) Right hand (RH) Pick up Unscrew

Definition 1.5.2: Decomposition breaks one whole problem into smaller, self-contained parts.

In the jam sandwich example, decomposition means identifying every ingredient required and every step the robot must take to end up with a sandwich.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.2 — pattern recognition groups what decomposition finds

A first pass at the jam sandwich problem

IngredientsEquipmentActions
BreadPlateRepeat x times
JamKnifeLeft hand (LH)
ButterRight hand (RH)
Pick up
Unscrew

Table 1.5.1: A first pass at decomposing and grouping the jam sandwich problem.

Read it: the things decomposition turned up sort naturally into ingredients, equipment, and actions — the more you think of, the clearer the final instructions will be.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

Insight — categories are compression

Twelve unrelated facts become three groups.

Once "pick up," "unscrew," and "spread" are all filed under actions, you stop tracking twelve unrelated facts. That is the entire trick — pattern recognition makes a big problem small enough to hold.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.2 — Practice

Try It Now 1.5.2

Try It Now 1.5.2

Lucía has to get to school on time tomorrow. Decompose her problem into at least six smaller tasks, then group those tasks into two or three categories of your own choosing.

One reasonable answer — the night before: pick clothes, pack the bag, charge the phone, set the alarm. The morning: wake up, eat breakfast, check the bus time. The trip: walk to the stop, board the bus. Half of her tasks turn out to belong to the night before — the sort of thing you only see once the problem has been taken apart.

1.5

§1.5.3 — pulling out what matters

Abstraction means pulling out the important details and identifying the principles that carry over to other problems or situations.

Keep what matters. Discard the rest.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.3 — a simplified representation, not the whole system

Definition 1.5.3: Abstraction

Definition 1.5.3 — Abstraction

Abstraction is a simplified representation of a complex system or phenomenon that keeps the details relevant to the problem at hand and discards the rest.

In the jam sandwich example, abstraction means forming an idea of what the sandwich should look like — a model of the desired outcome, with the details simplified away.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.3 — layers of abstraction

Each layer only worries about its own job

Ask a generative AI tool for help: you interact through a plain interface and see none of the underlying complexity. Your prompt is handled by the application's logic, then processed at the back end and returned — each layer serving a separate role, invisibly to you.

Figure 1.5.5 — Abstraction layers: a GenAI round trip A front-end outline (laptop, Web framework) and a back-end outline (Language framework over Language model, joined by Input-down and Output-up arrows) sit side by side, linked by Input-left and Output-right arrows between them. Below the front end, a User sends a Prompt down and receives a Generated response up. An accent dot travels User to front end to back end to Language model, pulses in place while it processes, then retraces the same path back to the User. Front end Webframework Back end Languageframework Languagemodel Input Output Input Output User Prompt Generatedresponse

Figure 1.5.5: When using GenAI, a user interacts with the interface while the application processes the prompt with layers of abstraction on the back end.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

Context Pause — you already trust abstraction constantly

You drive a car without knowing how the engine mixes fuel.

You send a message without knowing how it is routed. Abstraction is not a programming trick; it is the only reason any complicated system is usable at all.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.3 — Practice

Try It Now 1.5.3

Try It Now 1.5.3

You are describing a bus route to Priya, who moved to your town last week and has never taken it. Name two details you would keep for her and two you would leave out, and say why.

Keep: the stop where Priya gets on, and the stop where she gets off — without those the description is useless. Leave out: the colour of the bus and the name of every street it turns down. The test for abstraction is always the same: does dropping this detail change the action the reader has to take? If not, drop it.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.4 — a plan, written down before it has a language

Definition 1.5.4: Algorithm

Definition 1.5.4 — Algorithm

An algorithm is a finite, ordered sequence of unambiguous instructions that solves a problem or completes a task.

Algorithms are most commonly written as either pseudocode — a mixture of ordinary language and high-level programming ideas — or a flowchart, which shows the flow of decisions visually. Either is fine; it comes down to preference.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.4 — indentation shows what belongs inside what

Definition 1.5.5: Pseudocode

Definition 1.5.5 — Pseudocode

Pseudocode is a description of a program's steps written in plain language and arranged like code, with indentation showing which steps belong inside which. It is not written in any programming language and cannot be run.

Definition 1.5.5 — Pseudocode Six-line pseudocode listing with the two lines nested inside the while indented one step. A bracket draws in to enclose the indented pair, then two labels appear in turn: one naming the bracketed lines as repeating inside the while, the other naming the final unindented line as running once. set total to 0 set i to 1 while i is 5 or less add i to total add 1 to i print total inside the while - repeats outside - runs once

Definition 1.5.5: Pseudocode: indentation shows containment, so the indented lines live inside the while and the unindented one runs once.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.4 — putting the two conventions to work

Worked example

Example 1.5.1 — Pseudocode for a decision

Write pseudocode that decides whether someone may vote, based on their age.


ask the user for their age
if age is 18 or more
    print "You may vote"
otherwise
    print "Too young to vote"

Note what this does not say: nothing about how to ask, what a variable is, or which language this will become. The plan is right or wrong on its own terms, and you can check it by reading it to somebody.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

Context Pause — no compiler is the point

No machine checks it.

Pseudocode is worth writing precisely because no machine checks it. A syntax error tells you nothing about whether your plan makes sense. Reading five lines of plain English to a classmate finds "you never told it to stop" far faster than a debugger will.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.4 — Practice

Try It Now 1.5.4

Try It Now 1.5.4

Write pseudocode for finding the largest of three numbers. Use indentation to show which steps are inside a decision.

set largest to the first number
if the second number is bigger than largest
    set largest to the second number
if the third number is bigger than largest
    set largest to the third number
print largest

One correct answer — others work too. Pseudocode has no single right form, only clearer and less clear ones.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.5 — the same plan, drawn as a picture

Definition 1.5.6: Flowchart

Definition 1.5.6 — Flowchart

A flowchart is a diagram of a program's steps, using ovals for start and end, rectangles for actions, and diamonds for decisions, connected by arrows showing the order of execution.

Figure 1.5.7 — Flowchart symbols A ruled two-column table. The tinted header row reads Symbol and Instruction. Row 1 pairs a stadium (rounded rectangle) outline with Start/end. Row 2 pairs a rectangle outline with Task (e.g., spread jam). Row 3 pairs a diamond outline with Decision (e.g., do you want butter?). Row 4 pairs a down-right arrow with Direction of flow. Static figure, no motion. Symbol Instruction Start/end Task (e.g., spread jam) Decision (e.g., do you want butter?) Direction of flow

Figure 1.5.7: The symbols used in a flowchart are associated with their instructions.

The diamond has one way in and two ways out, and the two paths join up again afterwards — that shape is selection, drawn.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.5 — Practice

Try It Now 1.5.5

Try It Now 1.5.5

Sketch a flowchart for this task: get a number; if it is even, print "even"; otherwise print "odd". Name the shape you used for each step.

Five shapes, in order — Oval: Start. Rectangle: get the number. Diamond: is the number even? Two exits, yes and no. Rectangle on each branch: print "even" / print "odd". Oval: End, with both branches joining back together before it. A flowchart whose paths never meet again has two endings, which almost always means a step was forgotten.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.6 — a function that calls itself

Definition 1.5.7: Recursion

Definition 1.5.7 — Recursion

Recursion is a technique in which a function calls itself on a smaller version of the same problem, stopping at a base case — an input simple enough to answer directly without calling itself again.

Figure 1.5.8 — Iterative-sum flowchart Start, an initialization box, and a decision diamond sit on a left spine; the diamond's Yes branch runs right into a loop box whose own exit runs up and left to rejoin the spine just above the diamond, while the No branch runs down into Print Sum and End. A marker starts at Start, reaches the diamond, rides the loop twice (a second and third arrival at the diamond), and only on the third arrival takes No down to Print Sum and End. Start End i = 0, Sum = 0Read N Sum = Sum + ii = i + 1 Print Sum If i <= N Yes No

Figure 1.5.8: A flowchart represents an iterative solution for adding n numbers.

Comparing the two is a good way to see what recursion actually buys you: fewer moving parts in the code, at the cost of some work moving into memory where you cannot see it.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

Insight — deferred, not repeated

A chain of deferred operations, not a loop.

recursiveSum(10) cannot finish until recursiveSum(9) answers, and so on down. Those pending operations are held in memory until the base case lets the chain unwind. Leave out the base case and the chain never ends.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.6 — Practice

Try It Now 1.5.6

Try It Now 1.5.6

Run the code below. It is missing its base case. Predict what will happen before you press Run, then add the base case so it prints 55.

function recursiveSum(x) {
  return x + recursiveSum(x - 1);
}
console.log(recursiveSum(10));

Without a base case, x keeps decreasing past 0 forever: RangeError: Maximum call stack size exceeded. The fix is the missing stopping condition:

function recursiveSum(x) {
  if (x === 0) { return 0; }
  return x + recursiveSum(x - 1);
}
console.log(recursiveSum(10));  // 55
Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.7 — every browser has a JavaScript engine built in

Where JavaScript Runs

Definition 1.5.8 — Developer Console

The developer console is a panel built into the browser where JavaScript can be typed and run immediately, and where error messages and console.log output appear. It is opened with F12 in most browsers.

For anything you want to keep, you use a code editor — a text editor built for code, which colours your syntax and indents for you. The console is a scratchpad; the editor holds the program.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

Insight — the boxes on this page are both at once

An editor and a console at the same time.

The runnable boxes in this book are a third option, and a deliberate convenience — you can change an example and run it without leaving the page. Everything in them is ordinary JavaScript and behaves the same way anywhere else.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.7 — the browser console

Try It Now 1.5.7

Try It Now 1.5.7

Open your browser's console with F12 and type 2 + 2 * 3, then press Enter. Then type it again as (2 + 2) * 3. What are the two answers, and what does the difference tell you?

The first prints 8, the second prints 12. Multiplication happens before addition unless parentheses say otherwise. The useful part is not the arithmetic — it is that you settled the question in about four seconds without writing a file, saving it, or reloading anything. That is what the console is for.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.8 — the browser tells you what happened

Reading an Error Message

Uncaught ReferenceError: totl is not defined
    at line 3
  1. The kindReferenceError. A name was used that does not exist.
  2. The detailtotl is not defined. It names the exact thing it could not find.
  3. The place — the line number.

That message is telling you there is a typo, and telling you what the typo says. The fix is to compare totl with the name you meant.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

Context Pause — describing the problem often solves it

"It doesn't work" is not a description.

"It says ReferenceError: totl is not defined on line 3" describes a problem, and often answers it while you are typing it out. Reading the message is the first debugging step and it is free.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.8 — reading an error message

Try It Now 1.5.8

Try It Now 1.5.8

Run the code below, read the error it produces, and say which of the three parts of the message told you where to look. Then fix it.

let greeting = "hello";
console.log(gretting);

The error: Uncaught ReferenceError: gretting is not defined. The detail is the part that solves it — the name it could not find is spelled with the letters transposed. The place narrows it to the line; the kind tells you it is a name problem rather than a value problem. Fix: console.log(greeting);

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.9 — belief versus reality

Definition 1.5.9: Debugging

Definition 1.5.9 — Debugging

Debugging is the process of finding and fixing the cause of incorrect behaviour in a program. Its basic technique is to compare what you believe the program is doing with what it is actually doing.

Testing works by taking turns: one person reads out each instruction, the other follows it exactly. Each instruction is a test case — and when one fails, debugging finds the source of the problem and fixes it.

Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5.9 — Practice

Try It Now 1.5.9

Try It Now 1.5.9

The code below should print the area of a rectangle 4 by 5, which is 20. Add console.log lines to find out what it is actually doing, then fix it.

let width = 4;
let height = 5;
let area = width + height;
console.log("The area is " + area);

Printing the pieces shows width is 4, height is 5, area is 9 — both inputs are right, so the mistake is in the line that combines them: + should be *.

let width = 4;
let height = 5;
let area = width * height;
console.log("The area is " + area);  // 20
Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

Key Terminology

Key Terms (1 of 2)

  • Computational thinking — A problem-solving process that breaks a complex problem into smaller parts and devises systematic approaches to solve them.
  • Complex problem — A problem that is difficult because it involves many interrelated parts, and rarely has a simple solution.
  • Decomposition — Breaking a complex problem into smaller, self-contained parts that can be solved on their own.
  • Pattern recognition — Grouping the parts a decomposition turned up into categories, and spotting recurring structures across problems.
  • Inductive reasoning — Going from specific examples to a general principle.
  • Deductive reasoning — Drawing a conclusion that must be true if the premises are true.
  • Abstraction — A simplified representation of a complex system that keeps only the details relevant to the problem.
  • Data structure — A container that organizes and stores data efficiently, defining how it is arranged and accessed.
  • Algorithm — A finite, ordered sequence of unambiguous instructions that solves a problem or completes a task.
  • Pseudocode — A program's steps written in plain language and arranged like code, with indentation showing nesting. Not runnable in any language.
  • Flowchart — A diagram of a program's steps: ovals for start and end, rectangles for actions, diamonds for decisions, arrows for order.
  • Decision (diamond) — The flowchart shape with one way in and two ways out, labelled yes and no. Selection, drawn.
Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

Key Terminology

Key Terms (2 of 2)

  • Parallel execution — Running parts of an algorithm at the same instant on separate processors.
  • Concurrent execution — Interleaving separate tasks on one processor so they progress together without running at the same instant.
  • Recursion — A technique in which a function calls itself on a smaller version of the same problem, stopping at a base case.
  • Base case — The input simple enough for a recursive function to answer directly, which ends the chain of calls.
  • Developer console — The panel built into a browser for running JavaScript immediately and reading output and errors. Opened with F12.
  • Code editor — A text editor built for code, with syntax colouring and indentation help; where programs you intend to keep are written.
  • Error message — The browser's report of a failure, in three parts: the kind of error, the specific detail, and the line.
  • ReferenceError — The error raised when a name is used that does not exist; usually a typo or a missing declaration.
  • Test case — Specific input data used to check whether a program meets its requirements.
  • Debugging — Finding and fixing the cause of incorrect behaviour by comparing what you believe a program does with what it actually does.
  • console.log — The basic debugging tool: print a labelled value to check whether it is what you expected.
1.5
Program Design Tools and Environments · bookSHelf Intro to Programming§1.5

§1.5 — Conclusions

What to carry forward

The one idea

Plan first, in a form no compiler checks — pseudocode, a flowchart, or plain English read aloud to somebody — and only then translate the plan into JavaScript. Doing both at once means you can never tell which difficulty you are stuck on.

When the plan fails

Debugging is the same technique in reverse: compare what you believe the program is doing against what it is actually doing, one line at a time, until the mismatch is the only thing left.

Next: Chapter 2 — Control Flow, where these plans start branching and looping for real. Back to start.