| Lesson Plan |
| Grade: |
Date: 04/03/2026 |
| Subject: Computer Science |
| Lesson Topic: Show awareness of what a compiler has to do to translate recursive programming code |
Learning Objective/s:
- Describe the compiler phases involved in translating a recursive function.
- Explain how activation records are created and managed on the call stack.
- Identify when tail‑call optimisation can be applied and its effect on memory usage.
- Analyse a simple recursive example (e.g., factorial) and trace the generated code steps.
|
Materials Needed:
- Projector or interactive whiteboard
- Slides showing compiler phases and stack diagram
- Sample code worksheets (factorial example)
- IDE/compiler demo (e.g., gcc) on classroom computers
- Handout of activation‑record layout table
|
Introduction:
Begin with a quick question: What happens inside a program when a function calls itself? Review prior learning on recursion and call‑stack basics. Explain that today’s success criteria are to understand how a compiler translates such calls and to recognise optimisation opportunities.
|
Lesson Structure:
- Do‑now (5') – Students answer a short prompt about recursion behaviour.
- Mini‑lecture (10') – Overview of compiler phases for recursive code, using slides.
- Walkthrough (15') – Step‑by‑step translation of the factorial function, highlighting activation‑record creation.
- Guided practice (10') – In pairs, students annotate a worksheet showing stack changes for several recursive calls.
- Optimisation demo (10') – Demonstrate tail‑call optimisation with an example and discuss applicability.
- Check for understanding (5') – Quick quiz (Kahoot) on key concepts.
|
Conclusion:
Summarise how the compiler builds the call stack and where optimisation can reduce its depth. Have students write an exit‑ticket note describing a situation where tail‑call optimisation would be beneficial. Assign homework to research how another programming language handles recursion and optimisation.
|