Mission 1 · Spec 2.1.1 – 2.1.2
Thinking abstractly and thinking ahead
Abstraction and its different levels, and thinking ahead: inputs, outputs, preconditions, caching and reusable components.
- Starter 5 min
- Learn 15 min
- Lab 15 min
- Quiz 10 min
- Exam 15 min
Driving a car
You can drive a car without knowing how the engine works. What details are hidden from you? Why is that useful?
Reveal
Fuel injection, gearbox mechanics and electronics are hidden behind a steering wheel and pedals. Abstraction hides complexity so we can focus on what matters to us, just as a programming language hides machine code.
Key ideas
Abstraction
Removing unnecessary detail to focus on the essential features of a problem. A model or representation is an abstraction of reality. Abstraction differs from reality: it may lose accuracy.
Levels of abstraction
Layers such as high-level language → assembly → machine code → hardware, or the layers of a network model. Each layer hides the detail of the ones below.
Inputs, outputs and preconditions
Identify what data goes in and comes out. Preconditions are requirements that must be true before a subroutine runs (e.g. "the list must be sorted"). Stating them makes subroutines reusable and avoids unnecessary checks.
Caching
Storing data or instructions that are likely to be needed again, so they can be accessed faster, e.g. web browser caches. Can serve out-of-date data and is complex to manage.
Reusable program components
Subroutines, classes and libraries written once and reused. Save development time and are already tested.
Abstraction filter
You are modelling a train network timetable app.Thinking ahead
Exam-style questions
1. Explain the benefits of identifying preconditions when designing a subroutine.
[3 marks]Mark scheme
- Makes clear what must be true before the subroutine is called (1)
- so the subroutine doesn't need to include its own checks, making it simpler / shorter (1)
- so it can be reused more easily as its requirements are documented (1)
2. Describe one advantage and one disadvantage of caching.
[2 marks]Mark scheme
- Advantage: faster access to frequently used data / reduced load on the network or server (1)
- Disadvantage: cached data may be out of date / uses storage / complex to implement (1)
TUTOR NOTES
- Exam habit: in context questions, name the specific detail that is removed and explain why.
Mission 2 · Spec 2.1.3 – 2.1.5
Thinking procedurally, logically and concurrently
Decomposing problems into sub-procedures, identifying decision points, and working out which parts of a problem can happen at the same time.
- Starter 5 min
- Learn 15 min
- Lab 15 min
- Quiz 10 min
- Exam 15 min
Making breakfast
You need toast, a boiled egg and a cup of tea. What can you do at the same time? What must happen in order?
Reveal
Boil the kettle, the egg and the toast at the same time (concurrency). But you must boil the water before pouring the tea (ordering), and check whether the egg is done (a decision).
Key ideas
Thinking procedurally
Identify the components of a problem and of its solution; decompose it into sub-procedures; decide the order in which steps must happen.
Thinking logically
Identify the points where decisions are made, the conditions that affect them, and how each decision changes the flow through the program.
Thinking concurrently
Identify parts of a problem that can be tackled at the same time. Benefits: faster completion, better use of resources. Drawbacks: harder to program, parts may depend on each other, sharing data safely is difficult.
Concurrent or sequential?
An online shop is processing an order.Which kind of thinking?
Exam-style questions
1. A program applies a filter to every frame of a video. Explain how thinking concurrently could be applied, and one limitation.
[3 marks]Mark scheme
- Frames are independent, so several can be processed at the same time (1)
- e.g. split across multiple cores / threads, finishing faster (1)
- Limitation: overhead of splitting and recombining / limited by the number of cores / some effects depend on the previous frame (1)
TUTOR NOTES
- Misconception: concurrent means simultaneous on one core. Concurrency can be interleaved; parallelism is truly simultaneous.