Module 1: Thinking Like a Programmer
What Programming Really Is
Programming is often presented as something mysterious, done by people who think in ones and zeros. In reality, programming is the skill of giving a computer precise instructions to solve a problem. The hard part is rarely typing code; it is deciding exactly what should happen, in what order, in every situation. That way of thinking is useful well beyond software, and it is what this course teaches first.
Computers follow instructions exactly
A computer does not understand intentions. It does precisely what it is told, very quickly, and never gets bored. If you tell a person "add up today's sales", they know to skip the cancelled order and to ask if something looks odd. A computer will add up exactly the numbers you point it at, including the cancelled one, unless you said otherwise.
This is why programs are written in programming languages such as Python, JavaScript or Kotlin. These languages are much stricter than English. Every instruction has one meaning. A program is simply a text file of these instructions, which another program (an interpreter or compiler) turns into actions the machine can carry out.
Input, processing and output
Almost every program, from a calculator to M-Pesa's systems, follows the same basic pattern:
- Input: data comes in, typed by a user, read from a file, received from a network or a sensor.
- Processing: the program applies rules and calculations to the data.
- Output: results go out, shown on a screen, saved, printed or sent somewhere.
Here is a tiny but complete program in Python, the language used in this course. Do not worry about every symbol yet; read it line by line.
# Ask for a price and quantity, then show the total
price = float(input("Price per item (KES): "))
quantity = int(input("How many items? "))
total = price * quantity
print("Total to pay: KES", total)Line by line: the line beginning with # is a comment for humans and is ignored by the computer. The next two lines are input: they ask the user to type values and convert them into numbers. The fourth line is processing: it multiplies. The last line is output. If you type 250 and 3, the program prints Total to pay: KES 750.0.
Computational thinking
Computational thinking is the set of mental habits programmers use before and while writing code. It has four parts that you will practise throughout this course:
| Habit | What it means | Everyday example |
|---|---|---|
| Decomposition | Breaking a big problem into smaller ones | Planning a wedding as venue, food, guests, transport |
| Pattern recognition | Noticing similarities you can handle the same way | Every customer receipt has items, prices and a total |
| Abstraction | Ignoring details that do not matter for the task | A matatu route map shows stops, not every building |
| Algorithms | Writing clear step-by-step instructions | A recipe, or instructions for sending money by mobile |
Worked example: a business problem as a program
Imagine a small kiosk in Nairobi. The owner wants to know at the end of each day whether she made a profit. Thinking computationally:
- Decompose: she needs total sales, total costs and the difference.
- Recognise patterns: each sale is a quantity times a price; each cost is an amount.
- Abstract: customer names and the time of each sale do not matter for this question.
- Write the algorithm: add up sales, add up costs, subtract, then report "profit" or "loss".
Only now would a programmer start writing code. The code will be short, because the thinking already did the hard work.
What programming is not
Programming is not memorising every command; professionals look things up constantly in official documentation. It is not about being a mathematics genius; most everyday programming uses simple arithmetic and logic. And it is not a solitary activity: most software is built in teams, which is why writing clear, readable code matters as much as making it work.
Common mistakes to avoid
- Jumping straight into code. Spend a few minutes understanding the problem first. It saves hours.
- Expecting the computer to "know what you meant". If the result is wrong, the instructions were wrong or incomplete.
- Trying to learn everything before building anything. You learn programming by writing small programs, getting them wrong and fixing them.
- Comparing your first week to someone's tenth year. Every experienced programmer once struggled with the same basics.
Exercise
Choose a routine task from your work or home, such as paying a utility bill by mobile money or restocking a shelf. Write it as numbered steps so precise that someone who has never done it could follow them without asking questions. Then mark which steps are input, which are processing and which are output, and note one situation (for example, insufficient balance) your steps do not yet handle.
Key points
- Programming means giving a computer precise, unambiguous instructions
- Most programs follow input, processing, output
- Computational thinking: decomposition, pattern recognition, abstraction and algorithms
- Think through the problem before writing code; the code then becomes simpler