Course progress0%
Course content
18 min

Thinking Precisely Before Programming

Learn to transform human intentions into complete and unambiguous instructions.

By the end of this lesson

  • Recognize ambiguous instructions
  • Describe input, processing and output
  • Break a task into ordered steps
  • Test instructions manually

A machine does not guess your intention

Tell a person, “Sort these students by grade,” and they will make assumptions. A machine needs every important rule to be explicit.

  • Where do the students come from?
  • Are all grades valid?
  • Is the order highest to lowest?
  • What happens when two grades are equal?
  • What happens when a grade is missing?

Thinking like a machine means learning to remove ambiguity. It does not mean losing creativity.

Four questions for every task

  1. Input: What information is available?
  2. Output: What exact result is expected?
  3. Process: What ordered steps transform input into output?
  4. Exceptions: What unusual or invalid cases must be handled?

Example without code

Task: find the highest valid grade.

An algorithm is an ordered set of steps used to solve a problem. We can describe an algorithm using pseudocode, a readable notation that is not tied to a programming language.

In the example below:

  • INPUT identifies the information received
  • IF introduces a decision
  • OUTPUT identifies the result produced
  • END marks the end of the instructions
INPUT: a list of grades

IF the list is empty
  OUTPUT "No grade available"
OTHERWISE
  IGNORE every grade below 0 or above 20
  COMPARE the remaining grades
  OUTPUT the greatest grade
END

The words are written in uppercase only to make the important operations easy to recognize. Pseudocode has no single mandatory syntax. Its purpose is to make the reasoning clear.

Activity: instruct a robot

Write instructions for a robot to prepare a glass of water. The robot cannot infer where the glass is, whether it is clean or when it is full.

Now test your instructions by following them literally. Mark every place where you had to guess.

1. Find one clean, empty glass in the cupboard.
2. If no clean glass exists, stop and report the problem.
3. Place the glass under the water tap.
4. Open the tap slowly.
5. Stop when the glass is approximately three quarters full.
6. Close the tap.
7. Place the glass on the table.

Even this version contains assumptions. For example, the robot needs a way to recognize a glass and measure three quarters. Precise thinking is an iterative process.

Manual testing

Test an instruction set with at least three cases:

  • a normal case
  • an empty or missing input
  • an invalid input

You are already practicing an essential software engineering skill before writing code.

What you learned

  • Machines follow explicit instructions and do not infer human intention.
  • Every task needs defined inputs, outputs, steps and exceptions.
  • Pseudocode expresses logic without the syntax of a programming language.
  • Manual testing can expose missing decisions before implementation.

Knowledge check

  1. What is ambiguous about “show the best students”?
  2. Why should an empty input be tested?
  3. What is the difference between an algorithm and programming-language syntax?
  1. “Best” has no defined measure, number of students, ordering rule or treatment of equal grades.
  2. It reveals whether the instructions explain what happens when expected data does not exist.
  3. An algorithm describes the ordered logic of a solution. Syntax is the notation required to express that logic in a particular language.

Lesson complete?

Your progress is saved on this device.