Functions and Reusable Code
Computing · Programming & Algorithms · ages 10–13
Packaging steps into a named function (a custom block, a 'def') that can be reused, with inputs (parameters) that change what it does; keeping programs short and readable
At what age?
Usually at ages 10–13. The age is a guide: what decides whether a child is ready is the foundations below.
How do you know your child has learned it?
- Make a custom block or function and use it more than once
- Add an input to a function, such as the size of a shape it draws
- Explain why reusing a function is better than copying the same code
A quick check
Could your child make a 'draw star' block that takes a size, and use it to draw stars of different sizes?
What comes first?
- Breaking Problems into Parts (needed): Functions are how decomposed parts become code
- Variables: Programs That Remember (needed): Function inputs work like variables
What it leads to
Where to learn it
- Raspberry Pi Projects (Course · Chinese & English · ages 8–14 · Free): The Raspberry Pi Foundation's free project library (in Chinese too): build something that works, step by step, in Scratch, Python or HTML.
- Hello World! Computer Programming for Kids and Other Beginners (3rd edition) (Book · Chinese · ages 10–14): A Python introduction written by a father and son, in conversation, for parent and child to read and type along together; the third edition is fully updated to Python 3 and adds a chapter on the internet.