From Problem to Program
The hardest part of programming is modelling: deciding how to represent a real-world problem for a computer. A model is a deliberate simplification that captures what matters and ignores the rest.
Modelling follows three core steps. First, identify the data: what quantities and entities are involved, and what type is each?
| Entity | Data Representation | Example |
|---|---|---|
| Shopping Cart | List | Items with prices |
| Phone Book | Dictionary | Names to numbers |
The right structure makes the algorithm easy; the wrong one makes it painful.
Algorithms and Constraints
Second, define the algorithm: the step-by-step procedure transforming input into output. Write this in plain, structured pseudocode before real code to get the logic right without fighting syntax.
Third, state the assumptions and constraints (prices are non-negative, lists may be empty) so the program handles them properly.
Common pitfall: Diving straight into code before modelling. Always name your data types, sketch pseudocode steps, and then translate.